在flutter引入CupertinoAlertDialog总是报:The getter 'alertDialogLabel' was called on null

flutter使用CupertinoAlertDialog,点击弹出按键时报:

The getter 'alertDialogLabel' was called on null

跳入到上一层dialog.dart中的确有个label: localizations.alertDialogLabel,但是CupertinoAlertDialog没有该属性…
翻阅谷歌发现相同问题,简单尝试下,的确有效:
在flutter引入CupertinoAlertDialog总是报:The getter 'alertDialogLabel' was called on null_第1张图片
main.dart文件中加入localizationsDelegates这个属性,并在其中加入const FallbackCupertinoLocalisationsDelegate(),上面的三个是我加国际化引入的,不需要的不要加。并且在该文件下生成对应的类:

class FallbackCupertinoLocalisationsDelegate
    extends LocalizationsDelegate {
  const FallbackCupertinoLocalisationsDelegate();

  @override
  bool isSupported(Locale locale) => true;

  @override
  Future load(Locale locale) =>
      DefaultCupertinoLocalizations.load(locale);

  @override
  bool shouldReload(FallbackCupertinoLocalisationsDelegate old) => false;
}

现在,运行工程,CupertinoAlertDialog完美弹出。

你可能感兴趣的:(flutter)