No MaterialLocalizations found.和No MediaQuery widget found的解决方法
在使用showDialog
和showModalBottomSheet
时,发现它们不能直接写在 MaterialApp
的home属性下,会报如下错误:
Another exception was thrown: No MaterialLocalizations found.
或
Another exception was thrown: No MediaQuery widget found.
解决的办法就是将代码提取出来:
class MyApp extends StatelessWidget {@overrideWidget build(BuildContext context) {return MaterialApp(/// [home]这个地方,不能直接写dialog的代码,否则你会得到 "Another exception was thrown: No MaterialLocalizations found."/// 也不能写showModalBottomSheet的代码,否则你会得到 Another exception was thrown: No MediaQuery widget found./// 正确的做法就是把所有的内容都提取出去写。如下面这样把内容都提出来写到[HomePage]home: HomePage(),// 不能直接写dialog的代码);}
}
提取出来的代码放到HomePage下:
class HomePage extends StatefulWidget {@override_HomePageState createState() => _HomePageState();
}class _HomePageState extends State<HomePage> {@overrideWidget build(BuildContext context) {return Scaffold(appBar: AppBar(title: const Text('分享'),actions: <Widget>[IconButton(icon: Icon(Icons.share),onPressed: () {showModalBottomSheet(/*** showModalBottomSheet常用属性* shape 设置形状* isScrollControlled:全屏还是半屏* isDismissible:外部是否可以点击,false不可以点击,true可以点击,点击后消失* backgroundColor : 设置背景色*/backgroundColor: Colors.transparent,context: context,builder: (BuildContext context) {return RaisedButton(child: Text("Click"),onPressed: () {},);},);},),],),body: Center(),);}
}
No MaterialLocalizations found.和No MediaQuery widget found的解决方法相关推荐
- Failed resolution of: Landroid/support/v7/internal/widget/TintManager;异常解决方法
编译以下包的时候 compile 'com.android.support:appcompat-v7:23.4.0' compile 'com.android.support:support-v4:2 ...
- qt中出现out-of-line definition of 'Widget' does not match any declaration in 'Widget'问题的解决
Qt中出现out-of-line definition of 'Widget' does not match any declaration in 'Widget'问题的解决 1.简述 2.解决方法 ...
- 【错误记录】Flutter 使用 MediaQuery 适配全面屏报错 ( No MediaQuery widget ancestor found. )
文章目录 一.报错信息 二.解决方案 一.报错信息 需要使用 MediaQuery 获取当前的 Padding ; import 'package:flutter/material.dart';/// ...
- 【错误记录】Flutter 界面报错 ( No MediaQuery widget ancestor found. | Scaffold widgets require a MediaQuery )
文章目录 一.报错信息 二.解决方案 一.报错信息 Flutter 应用运行时报如下错误 : Launching lib\main.dart on Pixel 2 in debug mode... R ...
- flutter 报错之 No MediaQuery widget found.
这里通过一个HelloWorld app来展示如何创建一个Widget并展示出来,并区分Material和非Material环境. hello_word.dart里的代码如下: MaterialAp ...
- 解决方法 android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
第一次写博客 就是为了纪念这个困扰我一晚上的纠结问题 其实网上不少类似的问题 但都能看出个大概 什么LinearLayout转换 什么List转换出错 唯有这个很摸不着头脑 这里写出我的问题 ...
- 使用exe4j把jar转换成exe文件时,报错java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
在使用Eclipse 导出jar后,使用exe4j做成exe文件时保错,java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composit ...
- 百分比布局Design页面无法显示 :The following classes could not be found 解决方法
关于百分比布局Design页面 :The following classes could not be found: android.percentlayout.widget.PercentRelat ...
- 如何使用Flutter Widget构建响应式应用程序评论
Changes are usual for an app configuration. When the user rotates the phone either vertically or hor ...
最新文章
- MDEV Primer
- react-router 从 v2/v3 to v4 迁移(翻译)
- Redis 05_List列表 数组 Hash散列
- JSP的9个内置对象-response
- 论坛的搭建以及优化方案
- div和div之间画横线,如何在两个div之间画一条线?
- [COURSE_PTHE] 12. 黑盒网络服务器
- android screenshot 命令,android 截图,视频录制命令 screencap screenrecord screenshot
- POJO, VO什么的是个什么鬼?
- 删除Word模板文件
- 360视频:旋转球面投影RSP
- 西门子s7-200的PLC编程软件,帮助程序无法打开问题解决方法
- 报错:Exception opening socket
- 音声合成:音高、泛音、谐波、基频 到底是什么概念?
- 红米note3全网通 |2015112| 官方线刷包救砖包解账户锁屏幕锁
- 利用MATLAB仿真实现交通红绿灯识别的目的
- app中jeDate日期控件的使用
- 用户体验——以用户为中心的Web设计_Chapter3. 战略层:网站目标和用户需求
- 盲打打字php,讯飞输入法盲打键盘闪亮登场 是时候展示你真正的技术了
- 鸿蒙系统无缘华为手机,华为手机无缘鸿蒙系统!任正非隐藏锋芒,谷歌“逃过一劫”...