- 笔记:
1. PageController(
initialPage: 0, // 从0开始,0是第一个页面
viewportFraction: 1.0 // 100%
);
2. Hero的写法
createTile(Book book) => Hero(
tag: book.title,
child: Material(
elevation: 15.0,
shadowColor: Colors.yellow.shade900,
child: InkWell(
onTap: () {
Navigator.pushNamed(context, 'detail/${book.title}');
},
child: Image(
image: AssetImage(book.image),
fit: BoxFit.cover,
),
),
),
);
3. 一种写法
Widget buildStar(context, index) {...}
children: List.generate(starCount, (i) => buildStar(context, i)),
4. LayoutBuilder(builder: (context, constrains) {...}
这里的 constrains 自带的 constrains.maxHeight/maxWidth, 可以获取当前屏幕的尺寸
5. text 加上 divider 放在一起就是下划线的效果了。
6. 格式化代码 Linux: Ctrl + Shift + Alt + L
7. 使用 child: Placeholder(),看看当前在什么位置
8. 不同的类之间传递参数(只是其中一种写法而已):
传递方: Navigator.push(context, MaterialPageRoute(
builder: (_)=> ProductDetail(product: product)));
接收方: final Product product;
ProductDetail({this.product});
网友评论