main.dart 4.9 KB

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