对于未提供材料本地化的语言环境(si),如何避免出现“未找到材料本地化”错误?

时间:2019-09-19 14:03:38

标签: android flutter localization

我正在构建一个具有僧伽罗语(si)语言翻译的应用程序。 GlobalMaterialLocalizations.delegate不支持Locale('si')并引发此错误。

我只需要在僧伽罗语中显示我当前的翻译文本即可。我如何才能避免该错误并构建可与Locale('si')一起运行的应用?

The following assertion was thrown building AppBar(dirty, dependencies: [_InheritedTheme, _ModalScopeStatus, _LocalizationsScope-[GlobalKey#1d06e]], state: _AppBarState#58665):
No MaterialLocalizations found.

AppBar widgets require MaterialLocalizations to be provided by a Localizations widget ancestor.
Localizations are used to generate many different messages, labels,and abbreviations which are used by the material library. 
To introduce a MaterialLocalizations, either use a  MaterialApp at the root of your application to include them automatically, or add a Localization widget with a MaterialLocalizations delegate.

这是我的main.dart文件

import 'package:flutter/material.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:test_flutter/pages/home.dart';
import 'package:test_flutter/routes.dart';

import 'l10n/app_translations_delegate.dart';
import 'l10n/languages.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        locale: Locale('si'),
        title: 'MyApp',
        localizationsDelegates: [
          const AppTranslationsDelegate(),
          GlobalMaterialLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: Languages.getAllLocales(),
        routes: {
          RouteName.home: (context) => HomePage(),
        },
        initialRoute: RouteName.home,
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ));
  }
}

0 个答案:

没有答案