Skip to content

Commit cf6041c

Browse files
committed
Using simpler method of dialog - works with mobile too. WIP
1 parent 1b80cc0 commit cf6041c

File tree

2 files changed

+222
-490
lines changed

2 files changed

+222
-490
lines changed

example/lib/main.dart

Lines changed: 88 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -49,97 +49,94 @@ class _MyHomePageState extends State<MyHomePage> {
4949
appBar: AppBar(
5050
title: const Text('VSC Datetime Field Demo'),
5151
),
52-
body: Focus(
53-
onFocusChange: (f) => debugPrint('One of the fields has focus=$f'),
54-
child: SingleChildScrollView(
55-
child: Center(
56-
child: Container(
57-
padding: const EdgeInsets.fromLTRB(30, 30, 30, 30),
58-
width: 500,
59-
child: Column(
60-
crossAxisAlignment: CrossAxisAlignment.start,
61-
children: [
62-
ElevatedButton(
63-
onPressed: () => _valueController.value = DateTime.now(),
64-
child: const Text('Set date/time on fields')),
65-
const SizedBox(height: 30),
66-
VscDatetimeField(
67-
type: VscDatetimeFieldType.date,
68-
valueController: _valueController,
69-
textFieldConfiguration: const TextFieldConfiguration(
70-
decoration: InputDecoration(
71-
label: Text('Date only'),
72-
)),
73-
onValueChanged: (value) =>
74-
debugPrint('Date only field value: $value'),
75-
minValue: DateTime.parse('2020-02-15'),
76-
maxValue: DateTime.parse('2025-12-15'),
77-
),
78-
const SizedBox(height: 30),
79-
VscDatetimeField(
80-
type: VscDatetimeFieldType.datetime,
81-
valueController: _valueController,
82-
textFieldConfiguration: const TextFieldConfiguration(
83-
decoration: InputDecoration(
84-
label: Text('Datetime'),
85-
)),
86-
onValueChanged: (value) =>
87-
debugPrint('Datetime field value: $value'),
88-
minValue: DateTime.parse('2020-02-15 08:00:00'),
89-
maxValue: DateTime.parse('2025-12-15 17:00:00'),
90-
),
91-
const SizedBox(height: 30),
92-
VscDatetimeField(
93-
type: VscDatetimeFieldType.time,
94-
valueController: _valueController,
95-
textFieldConfiguration: const TextFieldConfiguration(
96-
decoration: InputDecoration(
97-
label: Text('Time only'),
98-
)),
99-
onValueChanged: (value) =>
100-
debugPrint('Time field value: $value'),
101-
minValue: DateTime.parse('1970-01-01 08:00:00'),
102-
maxValue: DateTime.parse('2099-01-01 17:00:00'),
103-
),
104-
const SizedBox(height: 30),
105-
VscDatetimeField(
106-
type: VscDatetimeFieldType.date,
107-
valueController: _valueController,
108-
textFieldConfiguration: const TextFieldConfiguration(
109-
decoration: InputDecoration(
110-
label: Text('Date - Read-only'),
111-
)),
112-
onValueChanged: (value) =>
113-
debugPrint('Read-only date field value: $value'),
114-
readOnly: true,
115-
),
116-
const SizedBox(height: 30),
117-
VscDatetimeField(
118-
type: VscDatetimeFieldType.datetime,
119-
valueController: _interactiveValueController,
120-
textFieldConfiguration: const TextFieldConfiguration(
121-
decoration: InputDecoration(
122-
label: Text(
123-
'Independent Datetime with interacting valueController'),
124-
)),
125-
onValueChanged: (dt) =>
126-
_interactiveValueController.value = dt,
127-
),
128-
const SizedBox(height: 30),
129-
ElevatedButton(
130-
child: const Text('Show date picker dialog'),
131-
onPressed: () async {
132-
final selectedDateTime = await showDatePicker(
133-
context: context,
134-
initialDate: DateTime.now(),
135-
firstDate: DateTime.parse('2000-01-01'),
136-
lastDate: DateTime.parse('2026-01-01'),
137-
);
138-
debugPrint('Selected $selectedDateTime from dialog');
139-
},
140-
),
141-
],
142-
),
52+
body: SingleChildScrollView(
53+
child: Center(
54+
child: Container(
55+
padding: const EdgeInsets.fromLTRB(30, 30, 30, 30),
56+
width: 500,
57+
child: Column(
58+
crossAxisAlignment: CrossAxisAlignment.start,
59+
children: [
60+
ElevatedButton(
61+
onPressed: () => _valueController.value = DateTime.now(),
62+
child: const Text('Set date/time on fields')),
63+
const SizedBox(height: 30),
64+
VscDatetimeField(
65+
type: VscDatetimeFieldType.date,
66+
valueController: _valueController,
67+
textFieldConfiguration: const TextFieldConfiguration(
68+
decoration: InputDecoration(
69+
label: Text('Date only'),
70+
)),
71+
onValueChanged: (value) =>
72+
debugPrint('Date only field value: $value'),
73+
minValue: DateTime.parse('2020-02-15'),
74+
maxValue: DateTime.parse('2025-12-15'),
75+
),
76+
const SizedBox(height: 30),
77+
VscDatetimeField(
78+
type: VscDatetimeFieldType.datetime,
79+
valueController: _valueController,
80+
textFieldConfiguration: const TextFieldConfiguration(
81+
decoration: InputDecoration(
82+
label: Text('Datetime'),
83+
)),
84+
onValueChanged: (value) =>
85+
debugPrint('Datetime field value: $value'),
86+
minValue: DateTime.parse('2020-02-15 08:00:00'),
87+
maxValue: DateTime.parse('2025-12-15 17:00:00'),
88+
),
89+
const SizedBox(height: 30),
90+
VscDatetimeField(
91+
type: VscDatetimeFieldType.time,
92+
valueController: _valueController,
93+
textFieldConfiguration: const TextFieldConfiguration(
94+
decoration: InputDecoration(
95+
label: Text('Time only'),
96+
)),
97+
onValueChanged: (value) =>
98+
debugPrint('Time field value: $value'),
99+
minValue: DateTime.parse('1970-01-01 08:00:00'),
100+
maxValue: DateTime.parse('2099-01-01 17:00:00'),
101+
),
102+
const SizedBox(height: 30),
103+
VscDatetimeField(
104+
type: VscDatetimeFieldType.date,
105+
valueController: _valueController,
106+
textFieldConfiguration: const TextFieldConfiguration(
107+
decoration: InputDecoration(
108+
label: Text('Date - Read-only'),
109+
)),
110+
onValueChanged: (value) =>
111+
debugPrint('Read-only date field value: $value'),
112+
readOnly: true,
113+
),
114+
const SizedBox(height: 30),
115+
VscDatetimeField(
116+
type: VscDatetimeFieldType.datetime,
117+
valueController: _interactiveValueController,
118+
textFieldConfiguration: const TextFieldConfiguration(
119+
decoration: InputDecoration(
120+
label: Text(
121+
'Independent Datetime with interacting valueController'),
122+
)),
123+
onValueChanged: (dt) =>
124+
_interactiveValueController.value = dt,
125+
),
126+
const SizedBox(height: 30),
127+
ElevatedButton(
128+
child: const Text('Show date picker dialog'),
129+
onPressed: () async {
130+
final selectedDateTime = await showDatePicker(
131+
context: context,
132+
initialDate: DateTime.now(),
133+
firstDate: DateTime.parse('2000-01-01'),
134+
lastDate: DateTime.parse('2026-01-01'),
135+
);
136+
debugPrint('Selected $selectedDateTime from dialog');
137+
},
138+
),
139+
],
143140
),
144141
),
145142
),

0 commit comments

Comments
 (0)