博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
flutter Material示例与MediaQuery.of(context) called with a context that does not contain a MediaQuery.
阅读量:4093 次
发布时间:2019-05-25

本文共 4368 字,大约阅读时间需要 14 分钟。

报错:

flutter MediaQuery.of(context) called with a context that does not contain a MediaQuery.

原因:

Scaffold必须放在MaterialApp里面,否则会报错

正确示例:

import 'package:flutter/material.dart';main() => runApp(MyApp());//MaterialApp : 将根布局换成一个 StatelessWidget//Scaffold : 必须放在MaterialApp里面class MyApp extends StatelessWidget {  @override  Widget build(BuildContext context) {    return MaterialApp(      title: "Material",      home: LearnMaterial(),    );  }}class LearnMaterial extends StatefulWidget {  @override  State
createState() { return _LearnMaterial(); }}class _LearnMaterial extends State
{ @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text("material"), ), body: Column( children:
[ Center( child: Material( color: Colors.blueAccent, shape: BeveledRectangleBorder( //斜角矩形边框 side: BorderSide( width: 1.0, color: Colors.blueAccent, style: BorderStyle.none, ), borderRadius: BorderRadius.circular(50.0), ), child: Container( padding: EdgeInsets.all(20.0), child: Text('斜角矩形边框'), ), ), ), Center( child: Material( color: Colors.blueAccent, shape: BeveledRectangleBorder( //斜角矩形边框 side: BorderSide( width: 1.0, color: Colors.blueAccent, style: BorderStyle.none, ), borderRadius: BorderRadius.circular(10.0), ), child: Container( padding: EdgeInsets.all(20.0), child: Text('斜角矩形边框'), ), ), ), Center( child: Material( color: Colors.blueAccent, shape: BorderDirectional( start: BorderSide( color: Colors.yellow, width: 10.0, ), top: BorderSide( color: Colors.deepOrange, width: 10.0, ), end: BorderSide( color: Colors.black87, width: 10.0, ), bottom: BorderSide( color: Colors.purpleAccent, width: 10.0, )), child: Container( padding: EdgeInsets.all(30.0), child: Text('多彩边框'), ), ), ), Center( child: Material( color: Colors.blueAccent, shape: CircleBorder( side: BorderSide( color: Colors.yellow, width: 10.0, )), child: Container( padding: EdgeInsets.all(50.0), child: Text('圆形边框'), ), ), ), Center( child: Material( color: Colors.blueAccent, shape: RoundedRectangleBorder( side: BorderSide( color: Colors.purpleAccent, width: 5.0, ), borderRadius: BorderRadius.circular( 20.0), //如果[borderRadius]被指定,那么[type]属性不能是 [MaterialType.circle]。 ), child: Container( padding: EdgeInsets.all(30.0), child: Text('圆角矩形'), ), ), ), Center( child: Material( color: Colors.purpleAccent, elevation: 10.0, shadowColor: Colors.yellow, shape: StadiumBorder( side: BorderSide( color: Colors.brown, width: 5.0, )), child: Container( padding: EdgeInsets.all(30.0), child: Text('体育场形状'), ), ), ) ], )); }}

效果图:

在这里插入图片描述

转载地址:http://dpnii.baihongyu.com/

你可能感兴趣的文章
我在ubuntu19.01中,使用docker-compose启动docker
查看>>
fusionpbx在換了服务器主机后,或换了ip地址后,必须改的设置
查看>>
使用python-ESL开发呼叫系统
查看>>
我在djiango的单页文件中,使用邮件发送接口与功能
查看>>
在vue页面中,使用audio标签 播放音频和视频
查看>>
我的后台规范
查看>>
我的前端vue开发规范
查看>>
我在ubuntu19.1使用django-crontab 执行服务器定时任务
查看>>
vue 播放音频
查看>>
版本更新步骤与命令
查看>>
在centos和ubuntu中 安装 python-ESL
查看>>
在内网使用DBL落地网关,连接公网的freeswitch
查看>>
关于我的整个系统的一个调试
查看>>
django-email中, 本地配置和阿里云配置是不同的。
查看>>
debian中修改freeswitch的 sip默认端口,防盗打
查看>>
在django中, 更新数据库表的时候, 对非空字段,在makemigrations时, 经常要填写缺省值
查看>>
我的组织机构与权限分配
查看>>
跨服务器docker freeswitch录音路径设备方案
查看>>
正则表达式 字符含义
查看>>
sh: 0: getcwd() failed: No such file or directory
查看>>