0
点赞
收藏
分享

微信扫一扫

flutter出现NoSuchMethodError: The getter 'modalBarrierDismissLabel' was called on null解决方法

NoSuchMethodError: The getter 'modalBarrierDismissLabel' was called on null解决方法


问题描述:如果在MaterialApp里调用showCupertinoDialog显示弹出框,可能会遇到这个错误。

原因分析:就是Material主题下Context没有这个Cupertine主题的属性

解决方法:添加GlobalCupertinoLocalizations.delegate,如下代码所示

MaterialApp(
localizationsDelegates: [
GlobalCupertinoLocalizations.delegate, //添加这行即可解决问题
GlobalMaterialLocalizations.delegate,
GlobalWidgetsLocalizations.delegate,
],
)
注意:需要在pubspec.yaml添加localizations依赖,如下:
dependencies:
flutter_localizations:
sdk: flutter




举报

相关推荐

0 条评论