怎么把flutter 的textfield的这个改成中文啊

发布于 1周前 作者 phonegap100 最后一次编辑是 5天前 来自 问答

怎么把flutter 的textfield的这个改成中文这个其实非常简单,我们只需要配置一下国际化就好了

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'; 

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'),
      ],
    ),
  );
}
回到顶部