flutter showDatePicker showTimePicker显示中文日期
1、配置flutter_localizations依赖
找到pubspec.yaml配置flutter_localizations
dependencies:flutter:sdk:flutter
flutter_localizations:sdk:flutter
2、导入国际化的包 flutter_localizations
import'package:flutter_localizations/flutter_localizations.dart';
如果无效就安装一下flutter pub get
3、设置国际化
voidmain(){runApp(newMaterialApp(title:'app',theme:newThemeData(primaryColor:Colors.white,),home:newMyLoginWidget(),localizationsDelegates:[//此处 系统是什么语言就显示什么语言GlobalMaterialLocalizations.delegate,GlobalWidgetsLocalizations.delegate,],supportedLocales:[//此处 系统是什么语言就显示什么语言constLocale('zh','CH'),constLocale('en','US'),],),);}
4、要显示中文的控件设置:
_showDatePicker()async{vardate =await showDatePicker(context:context,initialDate:_datetime,firstDate:DateTime(1900),lastDate:DateTime(2050),locale:Locale('zh'), // 强制显示中文 如果报错就删除,跟随系统语言显示);if(date==null)return;print(date);setState((){_datetime=date;});}