flutter showDatePicker显示中文日期_Flutter时间控件显示中文
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、设置国际化
void main() { runApp( new MaterialApp( title: ‘app‘, theme: new ThemeData( primaryColor: Colors.white, ), home: new MyLoginWidget(), localizationsDelegates: [ //此处 系统是什么语言就显示什么语言 GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, ], supportedLocales: [ //此处 系统是什么语言就显示什么语言 const Locale(‘zh‘, ‘CH‘), const Locale(‘en‘, ‘US‘), ], ), ); }
4、要显示中文的控件设置:
_showDatePicker() async{ var date =await showDatePicker( context: context, initialDate: _datetime, firstDate:DateTime(1900), lastDate:DateTime(2050), locale: Locale(‘zh‘), // 强制显示中文 如果报错就删除,跟随系统语言显示 ); if(date==null) return; print(date); setState(() { _datetime=date; }); }
相关推荐
csdnYF 2020-11-15
SemiraChen 2020-10-10
YejiaSun 2020-09-27
csdnYF 2020-09-20
FrankAbagnale 2020-09-15
wmd看海 2020-07-27
szintu 2020-07-05
chaoxiao 2020-07-04
wmd看海 2020-06-27
龙衣 2020-06-26
龙衣 2020-06-09
龙衣 2020-06-08
wmd看海 2020-06-04
Samlss 2020-06-04
wmd看海 2020-06-04
csdnYF 2020-05-30
androidgjw 2020-05-28
wmd看海 2020-05-28
wmd看海 2020-05-19