Flutter笔记-引入CupertinoAlertDialog报‘The getter alertDialogLabel was called on null’问题

报错的主要是因为Flutter国际化和ios风格Dialog冲突造成的。

解决方案:
1、在MaterialApp中添加FallbackCupertinoLocalisationsDelegate

localizationsDelegates: [
   GlobalMaterialLocalizations.delegate,
   GlobalWidgetsLocalizations.delegate,
   // 在国际化时造成和Dialog冲突解决方案
   FallbackCupertinoLocalisationsDelegate(),
 ],

2、创建FallbackCupertinoLocalisationsDelegate类

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class FallbackCupertinoLocalisationsDelegate
    extends LocalizationsDelegate<CupertinoLocalizations> {
  const FallbackCupertinoLocalisationsDelegate();

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

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

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

到此冲突解决完成,再次运行即可看到弹窗效果。

参考资料:
https://juejin.im/post/5c417d626fb9a049ec6b5d44

你可能感兴趣的:(Flutter学习)