Time Picker
TimeOfDay selectedTime = TimeOfDay.now(); Future_selectTime(BuildContext context) async { final TimeOfDay picked_s = await showTimePicker( context: context, initialTime: selectedTime, builder: (BuildContext context, Widget child) { return MediaQuery( data: MediaQuery.of(context).copyWith(alwaysUse24HourFormat: false), child: child, );}); if (picked_s != null && picked_s != selectedTime ) setState(() { selectedTime = picked_s; }); }
import 'dart:async'; import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State{ DateTime selectedDate = DateTime.now(); Future _selectDate(BuildContext context) async { final DateTime picked = await showDatePicker( context: context, initialDate: selectedDate, firstDate: DateTime(2015, 8), lastDate: DateTime(2101)); if (picked != null && picked != selectedDate) setState(() { selectedDate = picked; }); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('date picker'), ), body: Center( child: Column( mainAxisSize: MainAxisSize.min, children: [ Text("${selectedDate.toLocal()}".split(' ')[0]), SizedBox(height: 20.0,), RaisedButton( onPressed: () => _selectDate(context), child: Text('Select date'), ), ], ), ), ); } }