main.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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: FlatButton(
  34. onPressed: () {
  35. DatePicker.showDatePicker(context, showTitleActions: true, locale: 'zh',
  36. onChanged: (date) {
  37. print('change $date');
  38. }, onConfirm: (date) {
  39. print('confirm $date');
  40. },
  41. pickerModel: DatePickerModel(
  42. minYear: 2000, maxYear: 2019, currentTime: DateTime(2017, 93)));
  43. },
  44. child: Text(
  45. 'show date time picker',
  46. style: TextStyle(color: Colors.blue),
  47. )),
  48. ),
  49. );
  50. }
  51. }