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. // This is the theme of your application.
  12. //
  13. // Try running your application with "flutter run". You'll see the
  14. // application has a blue toolbar. Then, without quitting the app, try
  15. // changing the primarySwatch below to Colors.green and then invoke
  16. // "hot reload" (press "r" in the console where you ran "flutter run",
  17. // or press Run > Flutter Hot Reload in IntelliJ). Notice that the
  18. // counter didn't reset back to zero; the application is not restarted.
  19. primarySwatch: Colors.blue,
  20. ),
  21. home: new HomePage(),
  22. );
  23. }
  24. }
  25. class HomePage extends StatelessWidget {
  26. @override
  27. Widget build(BuildContext context) {
  28. return Scaffold(
  29. appBar: AppBar(
  30. title: Text('Datetime Picker'),
  31. ),
  32. body: Center(
  33. child: Column(
  34. children: <Widget>[
  35. FlatButton(
  36. onPressed: () {
  37. DatePicker.showDatePicker(context, showTitleActions: true,
  38. onChanged: (date) {
  39. print('change $date');
  40. }, onConfirm: (date) {
  41. print('confirm $date');
  42. },
  43. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  44. locale: 'zh');
  45. },
  46. child: Text(
  47. 'show date picker',
  48. style: TextStyle(color: Colors.blue),
  49. )),
  50. FlatButton(
  51. onPressed: () {
  52. DatePicker.showTimePicker(context, showTitleActions: true,
  53. onChanged: (date) {
  54. print('change $date');
  55. }, onConfirm: (date) {
  56. print('confirm $date');
  57. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  58. },
  59. child: Text(
  60. 'show time picker',
  61. style: TextStyle(color: Colors.blue),
  62. )),
  63. FlatButton(
  64. onPressed: () {
  65. DatePicker.showDateTimePicker(context, showTitleActions: true,
  66. onChanged: (date) {
  67. print('change $date');
  68. }, onConfirm: (date) {
  69. print('confirm $date');
  70. },
  71. currentTime: DateTime(2008, 12, 31, 23, 12, 34),
  72. locale: 'zh');
  73. },
  74. child: Text(
  75. 'show date time picker (Chinese)',
  76. style: TextStyle(color: Colors.blue),
  77. )),
  78. FlatButton(
  79. onPressed: () {
  80. DatePicker.showDateTimePicker(context, showTitleActions: true,
  81. onChanged: (date) {
  82. print('change $date');
  83. }, onConfirm: (date) {
  84. print('confirm $date');
  85. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  86. },
  87. child: Text(
  88. 'show date time picker (English-America)',
  89. style: TextStyle(color: Colors.blue),
  90. )),
  91. ],
  92. ),
  93. ),
  94. );
  95. }
  96. }