Flutter(iOS) -“找不到 CupertinoLocalizations”,如何修复?

Fet*_*mos 10 localization ios dart flutter flutter-ios

我在我的 flutter 应用程序中使用 TextField。它在安卓上运行。但在 ios 上,当我尝试从剪贴板粘贴到字段中时,出现错误:

 No CupertinoLocalizations found.
_CupertinoTextSelectionControlsToolbar widgets require CupertinoLocalizations to be provided by a Localizations widget ancestor.
The cupertino library uses Localizations to generate messages, labels, and abbreviations.
To introduce a CupertinoLocalizations, either use a CupertinoApp at the root of your application to include them automatically, 
The specific widget that could not find a CupertinoLocalizations ancestor was: _CupertinoTextSelectionControlsToolbar
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

这是我的代码的一部分,主页:

return Localizations(
  locale: Locale('en'),
  delegates: [
    GlobalMaterialLocalizations.delegate,
    DefaultCupertinoLocalizations.delegate,
    DefaultWidgetsLocalizations.delegate,
  ],
  child: CupertinoTabScaffold(
     tabBar: CupertinoTabBar(...)
     ....
  )
Run Code Online (Sandbox Code Playgroud)

在每个选项卡中我都使用此页面:

 return MaterialApp(
 navigatorKey: navKey,    
 home: child,);
Run Code Online (Sandbox Code Playgroud)

我在每个选项卡中都有单独的导航。

我该如何解决?有任何想法吗?我会很感激

Aki*_*kif 35

GlobalCupertinoLocalizations您可以尝试将委托添加DefaultCupertinoLocalizations到您的delegates

delegates: [
  GlobalMaterialLocalizations.delegate,          
  // DefaultCupertinoLocalizations.delegate,
  GlobalCupertinoLocalizations.delegate, // Here !
  DefaultWidgetsLocalizations.delegate,
],
Run Code Online (Sandbox Code Playgroud)

编辑:

您可能也需要添加supportedLocales

supportedLocales: [
   const Locale('en'), // English
   // const Locale('de'), // German, etc.   
]
Run Code Online (Sandbox Code Playgroud)