main.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 in time zone ' +
  41. date.timeZoneOffset.inHours.toString());
  42. }, onConfirm: (date) {
  43. print('confirm $date');
  44. }, currentTime: DateTime.now(), locale: LocaleType.en);
  45. },
  46. child: Text(
  47. 'show date picker(custom theme &date time range)',
  48. style: TextStyle(color: Colors.blue),
  49. )),
  50. FlatButton(
  51. onPressed: () {
  52. DatePicker.showTimePicker(context, showTitleActions: true,
  53. onChanged: (date) {
  54. print('change $date in time zone ' +
  55. date.timeZoneOffset.inHours.toString());
  56. }, onConfirm: (date) {
  57. print('confirm $date');
  58. }, currentTime: DateTime.now());
  59. },
  60. child: Text(
  61. 'show time picker',
  62. style: TextStyle(color: Colors.blue),
  63. )),
  64. FlatButton(
  65. onPressed: () {
  66. DatePicker.showDateTimePicker(context, showTitleActions: true,
  67. onChanged: (date) {
  68. print('change $date in time zone ' +
  69. date.timeZoneOffset.inHours.toString());
  70. }, onConfirm: (date) {
  71. print('confirm $date');
  72. },
  73. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  74. locale: LocaleType.zh);
  75. },
  76. child: Text(
  77. 'show date time picker (Chinese)',
  78. style: TextStyle(color: Colors.blue),
  79. )),
  80. FlatButton(
  81. onPressed: () {
  82. DatePicker.showDateTimePicker(context, showTitleActions: true,
  83. onChanged: (date) {
  84. print('change $date in time zone ' +
  85. date.timeZoneOffset.inHours.toString());
  86. }, onConfirm: (date) {
  87. print('confirm $date');
  88. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  89. },
  90. child: Text(
  91. 'show date time picker (English-America)',
  92. style: TextStyle(color: Colors.blue),
  93. )),
  94. FlatButton(
  95. onPressed: () {
  96. DatePicker.showDateTimePicker(context, showTitleActions: true,
  97. onChanged: (date) {
  98. print('change $date in time zone ' +
  99. date.timeZoneOffset.inHours.toString());
  100. }, onConfirm: (date) {
  101. print('confirm $date');
  102. },
  103. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  104. locale: LocaleType.nl);
  105. },
  106. child: Text(
  107. 'show date time picker (Dutch)',
  108. style: TextStyle(color: Colors.blue),
  109. )),
  110. FlatButton(
  111. onPressed: () {
  112. DatePicker.showDateTimePicker(context, showTitleActions: true,
  113. onChanged: (date) {
  114. print('change $date in time zone ' +
  115. date.timeZoneOffset.inHours.toString());
  116. }, onConfirm: (date) {
  117. print('confirm $date');
  118. },
  119. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  120. locale: LocaleType.ru);
  121. },
  122. child: Text(
  123. 'show date time picker (Russian)',
  124. style: TextStyle(color: Colors.blue),
  125. )),
  126. FlatButton(
  127. onPressed: () {
  128. DatePicker.showDateTimePicker(context, showTitleActions: true,
  129. onChanged: (date) {
  130. print('change $date in time zone ' +
  131. date.timeZoneOffset.inHours.toString());
  132. }, onConfirm: (date) {
  133. print('confirm $date');
  134. },
  135. currentTime: DateTime.utc(2019, 12, 31, 23, 12, 34),
  136. locale: LocaleType.de);
  137. },
  138. child: Text(
  139. 'show date time picker in UTC (German)',
  140. style: TextStyle(color: Colors.blue),
  141. )),
  142. ],
  143. ),
  144. ),
  145. );
  146. }
  147. }