本地化

对系统空间做本地化(例如复制,粘贴等文本)

pubspec.yaml文件中操作:

dependencies:
  # 添加下面的内容
  flutter_localizations:
    sdk: flutter

Material App中添加语言

// 注意添加导入
import 'package:flutter_localizations/flutter_localizations.dart';

class _MainAppState extends State<MainApp> {

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // 添加下面两个属性
      localizationsDelegates: [
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate
      ],
      supportedLocales: [
        Locale('en', 'US'), // 美国英语
        Locale('zh', 'CN'), // 中文简体
      ],

      // 其它内容...
    );
  }
}