标签:import 国际 显示 data col pack picker sde ted
flutter showDatePicker showTimePicker显示中文日期
找到pubspec.yaml配置flutter_localizations
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
import ‘package:flutter_localizations/flutter_localizations.dart‘;
如果无效就安装一下flutter pub get
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‘),
],
),
);
}
_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;
});
}
flutter showDatePicker显示中文日期_Flutter时间控件显示中文
标签:import 国际 显示 data col pack picker sde ted
原文地址:https://www.cnblogs.com/zhaofeis/p/12356402.html