flutterdev
https://flutter.dev/docs/development/ui/layout
Aligning widgets
MainAxisAlignment
https://blog.csdn.net/BINGXIHEART/article/details/95077098
可以接着完善
row
1
2
3
4
5
6
7
8Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Image.asset('images/pic1.jpg'),
Image.asset('images/pic2.jpg'),
Image.asset('images/pic3.jpg'),
],
);Column
1
2
3
4
5
6
7
8Widget buildRow() => Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset('images/pic1.jpg'),
Image.asset('images/pic2.jpg'),
Image.asset('images/pic3.jpg'),
],
);
constraints
ConstrainedBox
The ConstrainedBox
imposes additional constraints from its constraints
parameter onto its child .
UnconstrainedBox
The screen forces the UnconstrainedBox
to be exactly the same size as the screen. However, the UnconstrainedBox
lets its child Container
be any size it wants
https://resocoder.com/2019/08/15/flutter-custom-icons-automatic-manual-way-icon-font-or-svg/
json and serializtion
1 | dependencies: |
flutter packages pub run json_model
1 | import 'dart:convert'; |
项目中采用第三种方法
使用json_model自动生成
1.在项目根目录新建jsons文件夹并将json数据新建成为文件,在lib目录下新建包名为models
注意:这两个文件夹的名字都必须为jsons和models
2、加入依懒
注意:这里添加完json_serializable相关依赖之后还添加了json_model的依赖,这就是快捷生成的关键,还有如果json中引用了其他model可以使用如下方式
{
“name”:”wendux”,
“father”:”$user”,//可以通过”$”符号引用其它model类
“friends”:”$[]user”,//可以通过”$[]”来引用数组
“keywords”:”$[]String”,//同上
“age”:20
}
3.完成上面的操作之后
在当前项目的根目录执行如下命令:flutter packages pub run json_model
控制台打印如下日志就成功了
注意:如果json文件中加了注释可能会报错,需要删除注释,错误信息如下
其实,我们也可以不使用命令行的方式自动生成,
用run([‘src=jsons’])的方法也可以,run方法为json_model暴露的方法
https://www.jianshu.com/p/f37d8546ab8f
- 修改包名后 pubspec.yaml
target file “lib/main_dev.dart” not found
1 | plugin: |
flutter自定义控件