main.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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(
  34. backgroundColor: Colors.blue,
  35. itemStyle: TextStyle(
  36. color: Colors.white, fontWeight: FontWeight.bold),
  37. doneStyle:
  38. TextStyle(color: Colors.white, fontSize: 16)),
  39. onChanged: (date) {
  40. print('change $date');
  41. }, onConfirm: (date) {
  42. print('confirm $date');
  43. }, currentTime: DateTime.now(), locale: LocaleType.zh);
  44. },
  45. child: Text(
  46. 'show date picker(custom theme &date time range)',
  47. style: TextStyle(color: Colors.blue),
  48. )),
  49. FlatButton(
  50. onPressed: () {
  51. DatePicker.showTimePicker(context, showTitleActions: true,
  52. onChanged: (date) {
  53. print('change $date');
  54. }, onConfirm: (date) {
  55. print('confirm $date');
  56. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  57. },
  58. child: Text(
  59. 'show time picker',
  60. style: TextStyle(color: Colors.blue),
  61. )),
  62. FlatButton(
  63. onPressed: () {
  64. DatePicker.showDateTimePicker(context, showTitleActions: true,
  65. onChanged: (date) {
  66. print('change $date');
  67. }, onConfirm: (date) {
  68. print('confirm $date');
  69. },
  70. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  71. locale: LocaleType.zh);
  72. },
  73. child: Text(
  74. 'show date time picker (Chinese)',
  75. style: TextStyle(color: Colors.blue),
  76. )),
  77. FlatButton(
  78. onPressed: () {
  79. DatePicker.showDateTimePicker(context, showTitleActions: true,
  80. onChanged: (date) {
  81. print('change $date');
  82. }, onConfirm: (date) {
  83. print('confirm $date');
  84. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  85. },
  86. child: Text(
  87. 'show date time picker (English-America)',
  88. style: TextStyle(color: Colors.blue),
  89. )),
  90. FlatButton(
  91. onPressed: () {
  92. DatePicker.showDateTimePicker(context, showTitleActions: true,
  93. onChanged: (date) {
  94. print('change $date');
  95. }, onConfirm: (date) {
  96. print('confirm $date');
  97. },
  98. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  99. locale: LocaleType.nl);
  100. },
  101. child: Text(
  102. 'show date time picker (Dutch)',
  103. style: TextStyle(color: Colors.blue),
  104. )),
  105. FlatButton(
  106. onPressed: () {
  107. DatePicker.showDateTimePicker(context, showTitleActions: true,
  108. onChanged: (date) {
  109. print('change $date');
  110. }, onConfirm: (date) {
  111. print('confirm $date');
  112. },
  113. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  114. locale: LocaleType.ru);
  115. },
  116. child: Text(
  117. 'show date time picker (Russian)',
  118. style: TextStyle(color: Colors.blue),
  119. )),
  120. ],
  121. ),
  122. ),
  123. );
  124. }
  125. }