flutter i18n插件在android studio 3.4.0中不起作用

时间:2019-06-25 13:06:02

标签: android-studio flutter

flutter i18n插件在android studio 3.4.0中不起作用 无法在Android Studio中自动生成i18n.dart文件 AS 3.4.0的版本 颤动版本1.5.4 颤振i18n版本1.0.2

1 个答案:

答案 0 :(得分:-1)

您可以使用以下方法。经过Flutter网路和行动装置的测试

将此内容包含在pubspec.yaml中

dependencies:
  #i18n
  flutter_i18n:

flutter:
  assets:
    - assets/i18n/

虚拟主页小部件:

class MyApp extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return new MaterialApp(
      //i18n stuff
      localizationsDelegates: [
        FlutterI18nDelegate(
          useCountryCode: false,
          fallbackFile: 'en',
          path: 'assets/i18n',
        ),
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      home: new LoginPage(),
    );
  }

将其放入assets / i18n / en.json

{
  "login_screen": {
    "button": {
      "login": "LOGIN"
    }
  }
}

现在使用这些字符串如下:

Text(FlutterI18n.translate(
    context, 'login_screen.button.login'))