-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdemo.dart
127 lines (117 loc) · 3.21 KB
/
demo.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import 'package:flutter/material.dart';
import 'package:flutter_my_picker_null_safety/flutter_my_picker.dart';
import 'package:flutter_my_picker_null_safety/common/date.dart';
class DemoPage extends StatefulWidget {
@override
_DemoPageState createState() => _DemoPageState();
}
class _DemoPageState extends State<DemoPage> {
late DateTime date;
String? dateStr;
@override
void initState() {
super.initState();
DateTime _date = new DateTime.now();
print(MyDate.format('yyyy-MM-dd HH:mm:ss', _date));
setState(() {
date = _date;
dateStr = MyDate.format('yyyy-MM-dd HH:mm:ss', _date);
});
}
_change(formatString) {
return (_date) {
print(MyDate.format(formatString, _date));
setState(() {
date = _date;
dateStr = MyDate.format(formatString, _date);
});
};
}
changeDate(_date) {
setState(() {
date = _date;
});
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 8.0),
width: MediaQuery.of(context).size.width,
child: Text(
'当前时间: ${dateStr ?? MyDate.format('yyyy-MM-dd HH:mm:ss', date)}',
textAlign: TextAlign.center,
),
),
_Button('年份选择器', () {
MyPicker.showPicker(
title: Text('标题'),
context: context,
current: date,
mode: MyPickerMode.year,
onChange: _change('yyyy'),
);
}),
_Button('月份选择器', () {
MyPicker.showPicker(
context: context,
current: date,
mode: MyPickerMode.month,
onChange: _change('yyyy-MM'));
}),
_Button('日期选择器', () {
MyPicker.showDatePicker(
header: Center(child: Text('自定义头部'),),
context: context,
current: date,
// mode: MyPickerMode.date,
isShowHeader: false,
start: '2012-08-12',
end: MyDate.getNow(),
onChange: _change('yyyy-MM-dd'), title: null,
);
}),
_Button('时间选择器', () {
MyPicker.showPicker(
context: context,
current: date,
mode: MyPickerMode.time,
// start: '00:20',
// end: '21:40',
onChange: _change('HH:mm'),
);
}),
_Button('日期时间选择器', () {
MyPicker.showDateTimePicker(
context: context,
background: Colors.black,
color: Colors.white,
current: date,
magnification: 1.2,
squeeze: 1.45,
offAxisFraction: 0.2,
onChange: _change('yyyy-MM-dd HH:mm'),
);
}),
],
);
}
}
typedef OnChangeButton();
class _Button extends StatelessWidget {
final OnChangeButton onPressed;
final String text;
_Button(
this.text,
this.onPressed,
);
@override
Widget build(BuildContext context) {
return RaisedButton(
onPressed: onPressed,
child: Text(text),
);
}
}