listView赢得了滚动中的滚动
我尝试创建一个可滚动的ListView,但由于各种原因,它无法正常工作。
我的目标是:创建一个连接到Firebase的列表视图。我的listView收集良好的数据,但是scoll是不可能的。
我的脚手架的身体:
body: const SingleChildScrollView(
child: RecipesInformations(),
),
我的小部件:
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: _recipesStream,
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasError) {
return const Text('Something went wrong');
}
if (snapshot.connectionState == ConnectionState.waiting) {
return const Text("Chargement recettes");
}
return ListView(
shrinkWrap: true,
children: snapshot.data!.docs.map((DocumentSnapshot document) {
Map<String, dynamic> data =
document.data()! as Map<String, dynamic>;
List tags = List.from(document["tags"]);
return Container(
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(color: const Color(0xFF011200)),
borderRadius: const BorderRadius.all(Radius.circular(8))),
margin: const EdgeInsets.only(
bottom: 32, left: 16, right: 16, top: 8),
padding: const EdgeInsets.all(32),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
data["title"],
overflow: TextOverflow.fade,
maxLines: 1,
softWrap: false,
style: Theme.of(context).textTheme.headline1,
)
],
),
],
));
}).toList(),
);
},
);
}
让我知道您是否需要更多信息。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
删除
SinglechildScrollview
可能会有所帮助。Removing
SingleChildScrollView
might help.使用 listView.builder.builder 简化事物并删除未经必要的嵌套scrolllviews 。这样的事情可以起作用:
Use ListView.builder to simplify things and remove unnecessary nested scrollviews. Something like this could work:
您需要使用
futorbuilder
代替
streambuilder
。,
cream> streambuilder
是一个基于与流的交互的最新快照。取而代之的是,将流转换为
tolist(tolist())
方法并在futurebuilder.future.future.future
so:snapshot.data
现在是list> list
QUERYSNAPSHOT
。因此,它将与迭代上的迭代有所不同:结果将是这样的东西:
You'd need to use
FutureBuilder
instead ofStreamBuilder
.From the docs, the
StreamBuilder
is a Widget that builds itself based on the latest snapshot of interaction with a Stream. So, only the last item is going to show up on the screen.Instead, transform the stream to a List with the
toList()
method and use it on theFutureBuilder.future
property like so:snapshot.data
now is aList
ofQuerySnapshot
. So, it's going to be a bit different to iterate over it:The result is going to be something like this:
在您
listView
构造函数中,setprimary:false
,因为您将其嵌套在singlechildscrollview
中。In you
ListView
constructor, setprimary: false
since you are nesting it inside of aSingleChildScrollView
.