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 ...
随机推荐
- react找到对象数组中指定的值
找到对象数组中指定的值var array = [ { label: "Custom", value: "0" }, ...
- mailaddr - 关于邮件地址的描述
DESCRIPTION 描述 本手册给出的是 Internet 使用的 SMTP 邮件地址的简要描述.这些地址的通常的格式是 user@domain 这里的域 (domain) 是分级的子域的列表,子 ...
- PHP7搭建项目遇到的坑
报错一:该网页无法正常运作情况原因记录 code 500 原因:由于php.ini配置文件中错误显示关闭导致 解决方法: 修改php.ini配置文件 display_errors = On displ ...
- Linux服务器安装系统之1-LSI阵列卡raid5配置方法
- Codeforces 955 LR询问 多次幂处理
A 模拟题 #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) ...
- 1130. Infix Expression (25)
Given a syntax tree (binary), you are supposed to output the corresponding infix expression, with pa ...
- redis安装篇
Redis简介 Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value数据库,并提供多种语言的API.从2010年3月15日起,Redis的开发工作 ...
- ipsec概念理解
互联网安全协议(英语:Internet Protocol Security,缩写:IPsec): 本质上一个协议包,透过对IP协议的分组进行加密和认证来保护IP协议的网络传输协议族(一些相互关联的协议 ...
- AGC007题解
发现自己思维能力又跟不上了...做题有点吃力...所以回归AGC刷题计划... AGC040506都写了一部分题然后懒得补全了,所以从07开始做吧.大概是从C开始. C 这也太人类智慧了吧... 我先 ...
- Oracle12c RAC RMAN异机恢复
######################################################## #编辑pfile文件initspdb.ora vi /oracle/app/oracl ...