main.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_datetime_picker/flutter_datetime_picker.dart';
  3. void main() => runApp(new MyApp());
  4. class MyApp extends StatelessWidget {
  5. // This widget is the root of your application.
  6. @override
  7. Widget build(BuildContext context) {
  8. return new MaterialApp(
  9. title: 'Flutter Demo',
  10. theme: new ThemeData(
  11. primarySwatch: Colors.blue,
  12. ),
  13. home: new HomePage(),
  14. );
  15. }
  16. }
  17. class HomePage extends StatelessWidget {
  18. @override
  19. Widget build(BuildContext context) {
  20. return Scaffold(
  21. appBar: AppBar(
  22. title: Text('Datetime Picker'),
  23. ),
  24. body: Center(
  25. child: Column(
  26. children: <Widget>[
  27. FlatButton(
  28. onPressed: () {
  29. DatePicker.showDatePicker(context,
  30. showTitleActions: true,
  31. minTime: DateTime(2018, 3, 5),
  32. maxTime: DateTime(2019, 6, 7),
  33. theme: DatePickerTheme(), onChanged: (date) {
  34. print('change $date');
  35. }, onConfirm: (date) {
  36. print('confirm $date');
  37. }, currentTime: DateTime.now(), locale: LocaleType.zh);
  38. },
  39. child: Text(
  40. 'show date picker',
  41. style: TextStyle(color: Colors.blue),
  42. )),
  43. FlatButton(
  44. onPressed: () {
  45. DatePicker.showTimePicker(context, showTitleActions: true, onChanged: (date) {
  46. print('change $date');
  47. }, onConfirm: (date) {
  48. print('confirm $date');
  49. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  50. },
  51. child: Text(
  52. 'show time picker',
  53. style: TextStyle(color: Colors.blue),
  54. )),
  55. FlatButton(
  56. onPressed: () {
  57. DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
  58. print('change $date');
  59. }, onConfirm: (date) {
  60. print('confirm $date');
  61. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.zh);
  62. },
  63. child: Text(
  64. 'show date time picker (Chinese)',
  65. style: TextStyle(color: Colors.blue),
  66. )),
  67. FlatButton(
  68. onPressed: () {
  69. DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
  70. print('change $date');
  71. }, onConfirm: (date) {
  72. print('confirm $date');
  73. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  74. },
  75. child: Text(
  76. 'show date time picker (English-America)',
  77. style: TextStyle(color: Colors.blue),
  78. )),
  79. FlatButton(
  80. onPressed: () {
  81. DatePicker.showDateTimePicker(context, showTitleActions: true, onChanged: (date) {
  82. print('change $date');
  83. }, onConfirm: (date) {
  84. print('confirm $date');
  85. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: LocaleType.nl);
  86. },
  87. child: Text(
  88. 'show date time picker (Dutch)',
  89. style: TextStyle(color: Colors.blue),
  90. )),
  91. ],
  92. ),
  93. ),
  94. );
  95. }
  96. }