一、关于类
flutter 有两种类:
一个 StatefulWidget类。
一个 State类。 StatefulWidget类本身是不变的,但是 State类在widget生命周期中始终存在.
Flutter Decoration背景设定
链接
BoxDecoration:实现边框、圆角、阴影、形状、渐变、背景图像
ShapeDecoration:实现四个边分别指定颜色和宽度、底部线、矩形边色、圆形边色、体育场(竖向椭圆)、 角形(八边角)边色
FlutterLogoDecoration:实现Flutter图片
UnderlineTabindicator:下划线
boxShadow: [
BoxShadow(color: Color(0xFFDAE0EE),
offset: Offset.zero, // 偏移 Offset(5.0, 5.0) x/y
blurRadius: 14.0, // 模糊程度
spreadRadius: 0.0) // 阴影大小
]
CustomPaint
CustomPaint
http 请求
http 请求那部分内容有两处 api 被废弃了,原因是 dart2 之后将变量改成小写驼峰形式了。
UTF8.decoder => utf8.decoder
json-decode => jsonDecode
sliver
SliverToBoxAdapter 当你想把一个非Sliver的Widget放在CustomScrollview里面的时候,你需要用这个包裹一下。
路由
Flutter当前路由属性详解
生命周期
1 Navigator.pop(context); 可以关闭 showModalBottomSheet;
2 加载顺序:init!! — refresh — onload(生命周期如下图)
StatefulWidget:ProductsManager
ProductsManager部件初始化
创建ProductsManagerState
调用ProductsManagerState中的initState方法
ProductsManagerState渲染
Products部件初始化
Products渲染
作者:NS_Royce
1.jpg
lifecycle.jpg
序列化和反序列化
1、使用 dart:convert手动序列化JSON
{
"name": "John Smith",
"email": "john@example.com"
}
Map user = JSON.decode(json);
2、反序列化
String json = JSON.encode(user);
Navigator.pushNamed
// 1 自定义类
Args args = new Args('classIdValue'); //自定义类
Navigator.pushNamed(
context,
'/xx', //route name
arguments: args);
// 接收
Args args = ModalRoute.of(context).settings.arguments;
// 需要context,可以写在build方法里
// 也可以用 ModalRoute.of(this.context).settings.arguments;
// 2 Map
//发送
Navigator.pushNamed(
context,
'/xx', //route name
arguments: {
'classId': 'classIdValue',
'lessonInfos': [{
'name': 'xxxname',
'currentIndex': 1,
'lessonId': 'xxxlessonId'}]});
// 接收
Map args = ModalRoute.of(context).settings.arguments;
// 3
//发送
Navigator.pushNamed(
context,
'/xx', //route name
arguments: id );
// 接收
String id = ModalRoute.of(context).settings.arguments;
报错
1、'_InternalLinkedHashMap
'_InternalLinkedHashMap' is not a subtype of type 'Map'
map['eventType'].cast()
Map.from(map['eventType'])
// 改前
final map = snapshot.value as Map // 'as' doesn't change the type, it's just an assertion.
// 改后
final map = new Map.from(snapshot.value);