main.dart 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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, onChanged: (date) {
  38. print('change $date');
  39. }, onConfirm: (date) {
  40. print('confirm $date');
  41. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34), locale: 'zh');
  42. },
  43. child: Text(
  44. 'show date picker',
  45. style: TextStyle(color: Colors.blue),
  46. )),
  47. FlatButton(
  48. onPressed: () {
  49. DatePicker.showTimePicker(context, showTitleActions: true, onChanged: (date) {
  50. print('change $date');
  51. }, onConfirm: (date) {
  52. print('confirm $date');
  53. }, currentTime: DateTime(2008, 12, 31, 23, 12, 34));
  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: '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. ],
  84. ),
  85. ),
  86. );
  87. }
  88. }