1、配置flutter_localizations依赖
找到pubspec.yaml配置flutter_localizations
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
1
2
3
4
5
6
7
2
3
4
5
6
7
2、导入国际化的包 flutter_localizations
import 'package:flutter_localizations/flutter_localizations.dart';
1
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'),
],
),
);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;
});
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14