flutter dialog异常Another exception was thrown: No MaterialLocalizations found
flutter dialog异常Another exception was thrown: No MaterialLocalizations found
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart'; void main() {
runApp(new RootLayout());
} class RootLayout extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new RootLayoutM();
}
} class RootLayoutM extends State<RootLayout> {
_showMyMaterialDialog(BuildContext context) {
print("_showMyMaterialDialog");
showDialog(
context: context,
builder: (context) {
return new AlertDialog(
title: new Text("title"),
content: new Text("内容内容内容内容内容内容内容内容内容内容内容"),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("确认"),
),
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("取消"),
),
],
);
});
} @override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Center(
child: new Text("show simple dialog",
style: new TextStyle(color: Color(0xFF00FF00))),
),
floatingActionButton: new FloatingActionButton(
child: new Text("showDialog"),
onPressed: () {
_showMyMaterialDialog(context);
}),
),
);
;
}
}
这里顶层的context所在的Widget的顶层Widget属于StatefulWidget为什么还不能显示dialog呢
这里发现
@override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Center(
child: new Text("show simple dialog",
style: new TextStyle(color: Color(0xFF00FF00))),
),
floatingActionButton: new FloatingActionButton(
child: new Text("showDialog"),
onPressed: () {
_showMyMaterialDialog(context);
}),
),
);
;
}
这个FloatingActionButton在外面包一层就可以了
class MyFloat extends StatelessWidget{
_showMyMaterialDialog(BuildContext context) {
print("_showMyMaterialDialog");
showDialog(
context: context,
builder: (context) {
return new AlertDialog(
title: new Text("title"),
content: new Text("内容内容内容内容内容内容内容内容内容内容内容"),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("确认"),
),
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("取消"),
),
],
);
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return new FloatingActionButton(
child: new Text("showDialog"),
onPressed: () {
_showMyMaterialDialog(context);
});
}
完整代码如下
import 'package:flutter/material.dart';
import 'package:scoped_model/scoped_model.dart'; void main() {
runApp(new RootLayout());
} class RootLayout extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new RootLayoutM();
}
} class RootLayoutM extends State<RootLayout> { @override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
body: new Center(
child: new Text("show simple dialog",
style: new TextStyle(color: Color(0xFF00FF00))),
),
floatingActionButton: new MyFloat(),
)
);
} } class MyFloat extends StatelessWidget{
_showMyMaterialDialog(BuildContext context) {
print("_showMyMaterialDialog");
showDialog(
context: context,
builder: (context) {
return new AlertDialog(
title: new Text("title"),
content: new Text("内容内容内容内容内容内容内容内容内容内容内容"),
actions: <Widget>[
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("确认"),
),
new FlatButton(
onPressed: () {
Navigator.of(context).pop();
},
child: new Text("取消"),
),
],
);
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return new FloatingActionButton(
child: new Text("showDialog"),
onPressed: () {
_showMyMaterialDialog(context);
});
} }
flutter dialog异常Another exception was thrown: No MaterialLocalizations found的更多相关文章
- flutter dialog异常Another exception was thrown: Navigator operation requested with a context that does not include a Navigator
我在使用flutter里的对话框控件的时候遇到了一个奇怪的错误 Another exception was thrown: Navigator operation requested with a c ...
- flutter SnackBar异常Another exception was thrown: Scaffold.of() called with a context that does not contain a Scaffold
代码如下: import 'package:flutter/material.dart'; void main() { runApp(MaterialApp( title: 'Returning Da ...
- Could not create the view: An unexpected exception was thrown的解决方法
MyEclipse下面的server窗口突然不能正常显示了,而且还显示Could not create the view: An unexpected exception was thrown(无法创 ...
- Python中的异常(Exception)处理
异常 当你的程序出现例外情况时就会发生异常(Exception).例如,当你想要读取一个文件时,而那个文件却不存在,怎么办?又或者你在程序执行时不小心把它删除了,怎么办?这些通过使用异常来进行处理. ...
- [C#] C# 知识回顾 - 你真的懂异常(Exception)吗?
你真的懂异常(Exception)吗? 目录 异常介绍 异常的特点 怎样使用异常 处理异常的 try-catch-finally 捕获异常的 Catch 块 释放资源的 Finally 块 一.异常介 ...
- myEclipse Could not create the view: An unexpected exception was thrown.
myEclipse 非正常关闭,打开后 service Explorer or Package Explorer 视图显示不出来.报“Could not create the view: An une ...
- poco json 中文字符,抛异常JSON Exception -->iconv 转换 备忘录。
起因 最近linux服务器通信需要用到json. jsoncpp比较出名,但poco 1.5版本以后已经带有json库,所以决定使用poco::json(linux 上已经用到了poco这一套框架). ...
- Python中获取异常(Exception)信息
异常信息的获取对于程序的调试非常重要,可以有助于快速定位有错误程序语句的位置.下面介绍几种python中获取异常信息的方法,这里获取异常(Exception)信息采用try...except...程序 ...
- (转)Could not create the view: An unexpected exception was thrown. 电脑突然断电,myeclipse非正常关闭,出现错误
问题:电脑突然断电,myeclipse非正常关闭,“Package Explorer”非正常显示,出现错误“Could not create the view: An unexpected excep ...
随机推荐
- NSURLSession断点下载
#import <Foundation/Foundation.h> @class XHDownLoadManager; #pragma mark - delegate Method @pr ...
- LabWindows/CVI 下载
LabWindows/CVI 是National Instruments 公司(美国国家仪器公司,简称NI 公司)推出的交互式C 语言开发平台.LabWindows/CVI 将功能强大.使用灵活的C ...
- 对数据集做标准化处理的几种方法——基于R语言
数据集——iris(R语言自带鸢尾花包) 一.scale函数 scale函数默认的是对制定数据做均值为0,标准差为1的标准化.它的两个参数center和scale: 1)center和scale默认为 ...
- nice - 改变执行程序的优先级
总览 (SYNOPSIS) nice [OPTION]... [COMMAND [ARG]...] 描述 (DESCRIPTION) 以 调整过的 调度优先级 运行 COMMAND. 如果 没给出 C ...
- 第二节,下载openwrt源码和编译环境
文章的开始先说两个重点 1.不要使用root用户编译,普通用户编译即可. 2.自行搭建梯子,以免编译失败. 一,进入虚拟机内的Ubuntu系统 点击左下角的显示应用程序,我们去修改一下Ubuntu的源 ...
- VB之Collection---Collection集合类
你看到的这个文章来自于http://www.cnblogs.com/ayanmw 由于要对一些数据进行处理,比较麻烦,实现某个算法要处理大量不同的不同类型的数据. 所以考虑到一些因素,又在使用VB6( ...
- Python 快排
def quick_sort(array,left,right): if left>=right: return low=left high=right key=array[low]#设置基准数 ...
- du df的用法
1,两者区别 du,disk usage,是通过搜索文件来计算每个文件的大小然后累加,du能看到的文件只是一些当前存在 的,没有被删除的.他计算的大小就是当前他认为存在的所有文件大小的累加和. df, ...
- Bloom Filter的算法
Bloom Filter的算法: 为了降低冲突的概念,Bloom Filter使用了多个哈希函数,而不是一个.创建一个m位BitSet,先将所有位初始化为0,然后选择k个不同的哈希函数.第i个哈希函 ...
- os模块 sys模块 json/pickle 模块 logging模块
目录 模块 1. os模块 2. sys模块 3. json和pickle模块 4. logging模块 (1)日志配置 (2)实际开发中日志的使用 模块 1. os模块 os模块有什么用 与操作系统 ...