This repository has been archived by the owner on Jun 25, 2023. It is now read-only.
/
main.dart
103 lines (93 loc) · 2.32 KB
/
main.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import 'package:flutter/material.dart';
import 'package:date_form_field/date_form_field.dart';
class TestScreen extends StatefulWidget {
TestScreen({Key key}) : super(key: key);
@override
_TestScreenState createState() => _TestScreenState();
}
class _TestScreenState extends State<TestScreen> {
DateTime initialDate = DateTime.now();
DateTime firstDate = DateTime.now();
DateTime lastDate = DateTime(2100);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('DateFormField'),
),
body: ListView(
padding: EdgeInsets.all(10),
physics: BouncingScrollPhysics(),
children: [
buildDefaulf(),
buildPadding(),
buildOutline(),
buildPadding(),
buildDateTime(),
buildPadding(),
],
),
);
}
Widget buildDefaulf() {
return DateFormField(
showPicker: showPicker,
decoration: InputDecoration(hintText: 'Select date'),
);
}
Widget buildDateTime() {
return DateFormField(
format: 'd/MM/yyyy h:mm a',
decoration: InputDecoration(
filled: true,
labelText: 'Date Time Picker',
helperText: 'format: d/MM/yyyy h:mm a',
prefixIcon: Icon(
Icons.event,
),
suffixIcon: Icon(
Icons.check_circle,
),
),
showPicker: () {
return showDateTimePicker(
context: context,
);
},
);
}
Widget buildOutline() {
return DateFormField(
format: 'EEEE, MMM, d yyyy',
initialValue: initialDate.toString(),
decoration: InputDecoration(
labelText: 'Date Picker',
helperText: 'format: EEEE, MMM, d yyyy',
border: OutlineInputBorder(),
suffixIcon: Icon(
Icons.check_circle,
),
),
showPicker: () {
return showDatePicker(
context: context,
initialDate: firstDate,
firstDate: firstDate,
lastDate: lastDate,
);
},
);
}
Future<DateTime> showPicker() async {
DateTime date = await showDatePicker(
context: context,
initialDate: firstDate,
firstDate: firstDate,
lastDate: lastDate,
);
return date;
}
Widget buildPadding() {
return SizedBox(height: 20);
}
}