【发布时间】:2019-01-25 06:36:47
【问题描述】:
我有一个水平的 listview.builder 小部件,列表中的每个孩子大约是总宽度的 90℅,我如何检测哪个小部件处于焦点。
这是我的小部件。
new ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: categories.length,
itemBuilder: (context, index) {
return new InkWell(
onTap: () {
Navigator
.of(context)
.push(new MaterialPageRoute(
builder: (_) => new StakePage(),
));
},
child: new Card(
child: new Container(
decoration: new BoxDecoration(
image: new DecorationImage(
fit: BoxFit.cover,
image: categories[index].cover,
colorFilter: new ColorFilter.mode(
Colors.black12,
BlendMode.screen),
),
),
constraints: new BoxConstraints(
maxWidth: 400.0,
maxHeight: 600.0),
height: size.height / 2,
width: size.width * 0.85,
),
),
);
}),
【问题讨论】:
-
可以分享代码吗?图片?
-
我认为你应该使用 PageController 和 PageView 而不是 ListView :docs.flutter.io/flutter/widgets/PageController-class.html
-
这没用,我需要一个可滚动的
-
什么意思? PageView 是可滚动的,这里有一个例子:gist.github.com/collinjackson/4fddbfa2830ea3ac033e34622f278824
-
我明白你的意思,但它必须是一个像照片中的列表一样的列表,而不是每页一个小部件。我已经解决了。我会稍后发布答案
标签: listview flutter flutter-layout