flutter 参数函数_Flutter 基本用法摘记
Flutter 基本用法摘记
2018, Jun 26
| 访问量: 次
记录用Flutter开发一些基本用法,基于Android Studio,持续更新…
控件、布局
Contain
new Container(
alignment: Alignment.center,
margin: new EdgeInsets.only(top: 83.0),
padding: new EdgeInsets.only(top: 14.0, left: 22.0, bottom: 14.0, right: 22.0),
child: new Text(
"Register/Login",
style: new TextStyle(
fontSize: 16.0,
color: const Color(0xffffffff),
),
),
decoration: new BoxDecoration(
color: const Color(0xFF03BEFD),
borderRadius: BorderRadius.circular(100.0),
),
)
Row
new Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
],
)
Column
Stack
Padding
Expanded
An Expanded widget must be a descendant of a Row, Column, or Flex, and the path from the Expanded widget to its enclosing Row, Column, or Flex must contain only StatelessWidgets or StatefulWidgets (not other kinds of widgets, like RenderObjectWidgets).
Row(
children: [
Container( /// 此组件在主轴方向占据48.0逻辑像素
width: 48.0
),
Expanded(
child: Container() /// 此组件会填满Row在主轴方向的剩余空间,撑开Row
)
]
)
See also:
不强制子组件填满可用空间的Flexible。
布局组件目录。
SingleChildScrollView
类似ScrollView
Text
new Text(
"Register/Login",
style: new TextStyle(
fontSize: 16.0,
color: const Color(0xffffffff),
),
)
TextField
new TextField(
style: new TextStyle(color: Colors.white),
decoration: InputDecoration(
hintText: "Enter your email",
hintStyle:new TextStyle(fontSize: 12.0,color: Colors.grey),
border: InputBorder.none, //去掉边框
/* labelText: "Email", //编辑框对应的标签名称,就是点击编辑框,文字会上浮的那个
labelStyle:new TextStyle(color: const Color(0xFF424242)),*/
)
)
Image
函数、参数
Row,Column->MainAxisAlignment
MainAxisAlignment.spaceBetween //假设有1-2-3三个图片,居中,左边到1的间距,3到右边的间距为0,1-2,2-3之间间距相同
MainAxisAlignment.spaceAround //假设有1-2-3三个图片,居中,1-2,2-3之间间距相同,且左边到1的间距,3到右边的间距的一半
MainAxisAlignment.spaceEvenly //假设有1-2-3三个图片,居中,图片间距等值分配
MainAxisAlignment.start //假设有1-2-3三个图片,居中及靠左,图片间距为0
MainAxisAlignment.end //假设有1-2-3三个图片,居中及靠右,图片间距为0
MainAxisAlignment.center //假设有1-2-3三个图片,居中,图片间距为0
new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center, //需要依赖外层的Center,否则不生效
children: [
new Text("you click:"),
new Text('$count'),
],),
),
垂直方向
Row,Column->CrossAxisAlignment
CrossAxisAlignment.start //假设有1-2-3三个图片,靠左及顶部,图片间距为0
CrossAxisAlignment.end //假设有1-2-3三个图片,靠左及底部,图片间距为0
CrossAxisAlignment.center //假设有1-2-3三个图片,居中及靠左,图片间距为0
水平方向
TextDirection (排列方式)
TextDirection.ltr //假设有1-2-3三个图片,图片排列方式为1-2-3
TextDirection.rtr //假设有1-2-3三个图片,图片排列方式为3-2-1
Text—–>overflow (排列方式)
TextOverflow.ellipsis //结尾省略号
Container—–>alignment (对齐方式)
Alignment.topLeft //假设一张图片,在一个比图大的布局里,则在布局里,靠左及顶部排列
Alignment.topCenter //假设一张图片,在一个比图大的布局里,则在布局里,居中及顶部排列
Alignment.topRight //假设一张图片,在一个比图大的布局里,则在布局里,靠右及顶部排列
...
Image—–>fit (图片填充方式)
BoxFit.cover //中间部分填满布局
BoxFit.fill //整张图填满
BoxFit.fitWidth //宽度填满
BoxFit.fitHeight //等比缩放适配高度
Container—–>decoration (描述如何绘制容器)
BoxDecoration({
this.color, //颜色 color: Colors.amberAccent
this.image, //背景图 image: new DecorationImage(image: new ExactAssetImage('images/mozi.jpeg'),fit: BoxFit.cover,)
this.border, //边框颜色 border: new Border.all( color: Colors.red,//边框颜色 width: 2.0,//边框宽度)
this.borderRadius, //边框圆角,new BorderRadius.all(new Radius.circular(50.0))
this.boxShadow, //阴影
this.gradient, //渐变
this.shape: BoxShape.rectangle //矩形,BoxShape.circle //圆形
})
return new Center(
child: new Container(
width: 50.0,
height: 50.0,
decoration: new BoxDecoration(
//背景色
color: const Color(0xff7c94b6),
//没有图片的小伙,注释掉image这个,用color背景也是可以看效果的
image: new DecorationImage(
image: new ExactAssetImage('images/lake.jpg'),
fit: BoxFit.cover,
),
//shape类型:rectangle|circle
shape: BoxShape.rectangle,
//边框颜色
border: new Border.all(
color: Colors.red,//边框颜色
width: 2.0,//边框宽度
),
),
),
);
Container—–>margin (外边距)
EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom) //各个角边距
EdgeInsets.all(double value) //边距
Container—–>padding (内边距)
EdgeInsets.fromLTRB(this.left, this.top, this.right, this.bottom) //各个角边距
EdgeInsets.all(double value) //边距
new Padding(
padding: new EdgeInsets.all(8.0),
child: const Card(child: const Text('Hello World!')),
)
ListView—–>scrollDirection(ListView 排列方向)
Axis.horizontal //水平排列
Axis.vertical //垂直排列
Container->Column->Expanded,导致均分右边有外边距
Column->Expanded,均分正常
其它
打印日志
print(),debugPrint()
在命令行里执行flutter run 或者 flutter logs 在控制台可以看到日志,也可以用adb logcat 进行日志查看及过滤
Container,Padding均可让子控件获得padding属性
flutter upgrade
问题
1:ListView放在Colum或者Row里面报错
Widget _bulidMyCenter(BuildContext context) {
return new Container(
child: new Column(
children: [
new ListView.builder(
itemCount:listData.length,
itemBuilder: (context, i) => rendUI(context, i),
),
],
)
);
}
I/flutter (29754): The following assertion was thrown during performResize():
I/flutter (29754): Vertical viewport was given unbounded height.
I/flutter (29754): Viewports expand in the scrolling direction to fill their container.In this case, a vertical
I/flutter (29754): viewport was given an unlimited amount of vertical space in which to expand. This situation
I/flutter (29754): typically happens when a scrollable widget is nested inside another scrollable widget.
I/flutter (29754): If this widget is always nested in a scrollable widget there is no need to use a viewport because
I/flutter (29754): there will always be enough vertical space for the children. In this case, consider using a Column
I/flutter (29754): instead. Otherwise, consider using the "shrinkWrap" property (or a ShrinkWrappingViewport) to size
I/flutter (29754): the height of the viewport to the sum of the heights of its children.
解决方案:
Widget _bulidMyCenter(BuildContext context) {
return new Container(
child: new Column(
children: [
new Flexible(child: new ListView.builder(
itemCount:listData.length,
itemBuilder: (context, i) => rendUI(context, i),
),),
],
)
);
}
2.TextField放在Row里面报错
new Row(
children: [
new Container(
child: new TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Please enter a search term'),
),
)
],
)
I/flutter (12955): The following assertion was thrown during performLayout():
I/flutter (12955): BoxConstraints forces an infinite width.
I/flutter (12955): These invalid constraints were provided to RenderOpacity's layout() function by the following
I/flutter (12955): function, which probably computed the invalid constraints in question:
I/flutter (12955): _RenderDecoration._layout.layoutLineBox (package:flutter/src/material/input_decorator.dart:750:11)
I/flutter (12955): The offending constraints were:
I/flutter (12955): BoxConstraints(w=Infinity, 0.0<=h<=Infinity)
解决方案:
new Row(
children: [
new Expanded(
child: new TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Please enter a search term'),
),
)
],
)
本文标题:Flutter 基本用法摘记
文章作者:Teisyogun
发布时间:2018-06-26 08:54:00 +0000
原始链接:
Newsletter
Subscribe here to get our latest updates
Email Address
flutter 参数函数_Flutter 基本用法摘记相关推荐
- python 装饰器 参数-python函数装饰器之带参数的函数和带参数的装饰器用法示例...
本文实例讲述了python函数装饰器之带参数的函数和带参数的装饰器用法.分享给大家供大家参考,具体如下: 1. 函数带多个参数 # 普通的装饰器, 打印函数的运行时间 def decrator(fun ...
- python装饰器函数-python函数装饰器之带参数的函数和带参数的装饰器用法示例
本文实例讲述了python函数装饰器之带参数的函数和带参数的装饰器用法.分享给大家供大家参考,具体如下: 1. 函数带多个参数 # 普通的装饰器, 打印函数的运行时间 def decrator(fun ...
- python函数和方法的入参格式有哪些_Python函数的参数常见分类与用法实例详解
本文实例讲述了Python函数的参数常见分类与用法.分享给大家供大家参考,具体如下: 1.形参与实参是什么? 形参(形式参数):指的是 在定义函数时,括号内定义的参数,形参其实就是变量名 实参(实际参 ...
- MSSQL Sql加密函数 hashbytes 用法简介
原文:MSSQL Sql加密函数 hashbytes 用法简介 转自:http://www.maomao365.com/?p=4732 一.mssql sql hashbytes 函数简介 hashb ...
- 字符串函数用法 php,PHP字符串函数print()的用法
print (PHP 4, PHP 5) print - 输出字符串 说明 int print ( string $arg ) 输出 arg. print 实际上不是一个函数(它是一个语言结构),因此 ...
- 【C 语言】指针 与 数组 ( 指针 | 数组 | 指针运算 | 数组访问方式 | 字符串 | 指针数组 | 数组指针 | 多维数组 | 多维指针 | 数组参数 | 函数指针 | 复杂指针解读)
相关文章链接 : 1.[嵌入式开发]C语言 指针数组 多维数组 2.[嵌入式开发]C语言 命令行参数 函数指针 gdb调试 3.[嵌入式开发]C语言 结构体相关 的 函数 指针 数组 4.[嵌入式开发 ...
- python用psf函数_Python 嵌套函数(高级用法)
Python 嵌套函数(高级用法) 一.嵌套函数(高级用法) 1.嵌套函数 函数的嵌套调用是在"函数调用中再调用其他函数".也就是说:函数嵌套允许在一个函数中调用另外一个函数.如下 ...
- php数组函数及用法,php数组函数 in_array 的用法及注意事项
php中操作数组的函数很多,in_array就是其中一个. in_array函数 用于检查是否存在一个值的数组,即它可以判断当前数组中是否存在一个指定的值. in_array (PHP 4, PHP ...
- 【转】typedef函数指针的用法(C++)
原文: typedef函数指针的用法(C++) 代码简化, 促进跨平台开发的目的. typedef 行为有点像 #define 宏,用其实际类型替代同义字. 不同点:typedef 在编译时被解释,因 ...
最新文章
- antd Tree 展开和默认选中
- layui 自定义排序_浅谈layui中table的sort排序
- 序列变换(Lis变形)
- 有趣又有用的皮托定理!
- Vue之Vue.set动态新增对象属性
- java 8 foreach_Java 8 forEach Stream()与旧版forEach循环
- python实战===生成随机数
- 区块链查比特币_登图区块链课堂——比特币矿机发展史
- ws2812b程序51单片机_51单片机串口通信程序详解
- python和c语言全局变量,Python如何实现C/C++全局变量?
- Map定义了几个用于插入和删除元素的变换方法
- owncloud个人私有云 一键安装包操作指南
- 使用redis保存验证码
- 网络规划设计师教程pdf版下载
- x,y直角坐标系转经纬度WGS-84坐标系
- android 阻尼动画,Android阻尼效果 | 自定义进阶之实现MIUI的拖动视差效果
- 机器人布里茨说什么_lol蒸汽机器人布里茨辅助玩法介绍 值得一看
- 5款知名bug管理工具
- HCIP之路IPV6
- 福州的宝贝原来都藏在这里