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

阅读 41

2022-05-16

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)

0 0 举报