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
posted @ 2020-09-27 11:35  yongfengnice  阅读(1212)  评论(0编辑  收藏  举报