Flutter笔记-引入CupertinoAlertDialog报‘The getter alertDialogLabel was called on null’问题
Posted 小溪彼岸
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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笔记-引入CupertinoAlertDialog报‘The getter alertDialogLabel was called on null’问题的主要内容,如果未能解决你的问题,请参考以下文章