【发布时间】:2019-10-08 21:04:37
【问题描述】:
当我使用 ListView 时,ListTile OnTap 正在工作。但是当我使用 ListWheelScrollView 时它不起作用。我的意思是它不会被窃听。视图发生变化。但我似乎无法点击它。我在很多地方和链接中寻找解决方案,但仍然找不到解决方案。
这些是我做的代码。
@override
Widget build(BuildContext context) {
return new ListWheelScrollView(
physics:FixedExtentScrollPhysics(),
children: getPostList(),
itemExtent: 100.0,
);
}
List<PostListItem> getPostList() {
return _postModal
.map((contact) => new PostListItem(contact))
.toList();
}
这就是我构建 ListTile 的地方
@override
Widget build(BuildContext context) {
return new ListTile(
onTap: () {
var route = new MaterialPageRoute(
builder: (BuildContext context) =>
new OnTapPost(value: _postModal.fullName),
);
Navigator.of(context).push(route);
},
leading: new Image.asset('assets/images/logo.png'),
title: new Text(_postModal.fullName),
subtitle: new Text(_postModal.email)
);
}
在上面的代码中,列表项没有被点击。但是,如果我将 ListWheelScrollView 替换为 ListView ,如下所示,它可以完美运行。
@override
Widget build(BuildContext context) {
return new ListView(
children: getPostList(),
);
}
List<PostListItem> getPostList() {
return _postModal
.map((contact) => new PostListItem(contact))
.toList();
}
【问题讨论】:
-
这可能是个问题,您现在只需要使用不同类型的列表。见github.com/flutter/flutter/issues/38803
-
我猜终于发布了解决方案。它在链接pub.dev/packages/clickable_list_wheel_view
标签: android dart flutter flutter-dependencies