RaisedButton(
onPressed: () async {
var result = await showDatePicker(
context: context,initialDate: DateTime.now(),firstDate: DateTime(2020),lastDate: DateTime(2021));
print('$result');
},)
showDatePicker(
selectableDayPredicate: (DateTime day) {
return day.difference(DateTime.now()).inDays < 2;
},...
)
showDatePicker(
builder: (context,child) {
return Theme(
data: ThemeData.dark(),child: child,);
},...
)
中文支持
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,GlobalWidgetsLocalizations.delegate,],supportedLocales: [
const Locale('zh','CH'),const Locale('en','US'),locale: Locale('zh'),...
)
showDatePicker(
locale: Locale('zh'),...
)
RaisedButton(
onPressed: () async {
showTimePicker(
context: context,initialTime: TimeOfDay.now());
},)
showTimePicker(
context: context,initialTime: TimeOfDay.now(),builder: (context,child) {
return MediaQuery(
data: MediaQuery.of(context)
.copyWith(alwaysUse24HourFormat: true),);
});
showTimePicker(
context: context,child) {
return Localizations(
locale: const Locale('zh'),delegates: <LocalizationsDelegate>[
GlobalMaterialLocalizations.delegate,]
);
});
var _dateTime = DateTime.now();
CupertinoDatePicker(
initialDateTime: _dateTime,onDateTimeChanged: (date) {
setState(() {
_dateTime = date;
});
},)
- time:只显示时间,效果:
4 | 14 | PM
- date:只显示日期,效果:
July | 13 | 2012
- dateAndTime:时间和日期都显示,效果:
Fri Jul 13 | 4 | 14 | PM
CupertinoDatePicker(
minimumDate: DateTime.now().add(Duration(days: -1)),maximumDate: DateTime.now().add(Duration(days: 1)),...
)
CupertinoDatePicker(
use24hFormat: true,...
)
CupertinoTimerPicker(
onTimerDurationChanged: (Duration duration){
},)
CupertinoTimerPicker(
mode: CupertinoTimerPickerMode.hm,...
)
var now = DateTime.now();
return Container(
height: 200,child: CupertinoTimerPicker(
initialTimerDuration: Duration(hours: now.hour,minutes: now.minute,seconds: now.second),onTimerDurationChanged: (Duration duration) {},),);