Flutter禁用滚动事件

在ScrollView或ListView中嵌套GridView创建二维布局的元素,但是GridView自带滚动属性,使得页面无法随着ScrollView或Listview滚动,所以我们需要禁用GridView的滚动属性。

所有滚动组件都有一个physics的属性,只要我们增加如下代码:

1
physics: new NeverScrollableScrollPhysics(),
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
new GridView.count(
physics: new NeverScrollableScrollPhysics(),
crossAxisCount: (orientation == Orientation.portrait) ? 3 : 4,
mainAxisSpacing: 20.0,
crossAxisSpacing: 4.0,
padding: const EdgeInsets.all(4.0),
childAspectRatio: (orientation == Orientation.portrait) ? 1.0 : 1.3,
children: photos.map((Photo photo) {
return new GridDemoPhotoItem(
photo: photo,
onBannerTap: (Photo photo) {
setState(() {
photo.isFavorite = !photo.isFavorite;
});
}
);
}).toList(),
);

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :