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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM