Firebase 为什么我的Firestore StreamBuilder在向上滚动时会跳过&x27;把它放在自定义滚动视图中?
出于某种原因,每当我尝试向上滚动时,我的StreamBuilder就会跳过整个容器。然而,当我从Firestore流中的某个点开始向上滚动时,它才开始跳过容器。大概是2000像素左右?不管怎样,重要的一点是,当我将普通容器仅与StreamBuilder放在同一场景中时,这种情况不会发生。只有当我将它放在CustomScrollView中时,才会出现这个问题(见下面的视频) 整个事情发生在我试图将StreamBuilder包装在列/列表视图中,以便将其他容器放在流容器之上之后。将其包装到列/列表视图中不起作用,因为在列中,另一个容器不会与流的其余部分一起向下滚动。在ListView中,StreamBuilder有自己独立的滚动系统 基本上,我的目标是有一个滚动的小部件的大列表。顶部将有一些与Firestore中的部分(位于底部)分开。单击其中一个Firestore容器后,我将进入另一个页面 这是我离实现目标最近的一次了,但是如果有别的办法,我很乐意听到Firebase 为什么我的Firestore StreamBuilder在向上滚动时会跳过&x27;把它放在自定义滚动视图中?,firebase,dart,google-cloud-firestore,flutter,Firebase,Dart,Google Cloud Firestore,Flutter,出于某种原因,每当我尝试向上滚动时,我的StreamBuilder就会跳过整个容器。然而,当我从Firestore流中的某个点开始向上滚动时,它才开始跳过容器。大概是2000像素左右?不管怎样,重要的一点是,当我将普通容器仅与StreamBuilder放在同一场景中时,这种情况不会发生。只有当我将它放在CustomScrollView中时,才会出现这个问题(见下面的视频) 整个事情发生在我试图将StreamBuilder包装在列/列表视图中,以便将其他容器放在流容器之上之后。将其包装到列/列表视
视频: 只有绿色容器来自Firestore StreamBuilder。不是红色或蓝色的。
代码:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:firebase_auth/firebase_auth.dart';
class GeneralTopicsPage extends StatefulWidget {
GeneralTopicsPage({this.user, this.googleSignIn, this.index});
final FirebaseUser user;
final GoogleSignIn googleSignIn;
var index;
@override
_GeneralTopicsPageState createState() => new _GeneralTopicsPageState();
}
class _GeneralTopicsPageState extends State<GeneralTopicsPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
pinned: true,
title: Text(
"Testing",
),
),
SliverPadding(
//Works perfectly fine.
padding: EdgeInsets.all(16.0),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
margin: EdgeInsets.all(20.0),
color: Colors.red,
height: 400.0,
child: Center(
child: Text(
"This is a normal, hardcoded Container in red and it works perfectly fine. Notice the lack of skipping when scrolling up.",
style: TextStyle(
color: Colors.white
),
textAlign: TextAlign.center,
),
),
);
},
childCount: 7,
),
),
),
SliverPadding(
//This is where it doesn't work as intended. Its behavior is separate from the containers located above and below it because it suddenly includes a StreamBuilder.
padding: EdgeInsets.all(16.0),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return StreamBuilder(
stream: Firestore.instance.collection("content").snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData) {
return Container(
child: Center(
child: CircularProgressIndicator(),
),
);
} else {
return Container(
margin: EdgeInsets.all(20.0),
color: Colors.green,
height: 400.0,
child: Center(
child: Text(
snapshot.data.documents[index]['title'],
style: TextStyle(
color: Colors.white
),
textAlign: TextAlign.center,
),
),
);
}
},
);
},
childCount: 8,
),
),
),
SliverPadding(
//Works perfectly fine.
padding: EdgeInsets.all(16.0),
sliver: SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
margin: EdgeInsets.all(20.0),
color: Colors.blue,
height: 400.0,
child: Center(
child: Text(
"This is a normal, hardcoded Container in blue and it works perfectly fine. Notice the lack of skipping when scrolling up.",
style: TextStyle(
color: Colors.white
),
textAlign: TextAlign.center,
),
),
);
},
childCount: 3,
),
),
),
],
),
);
}
}
导入'dart:async';
进口“包装:颤振/材料.省道”;
导入“包:cloud_firestore/cloud_firestore.dart”;
导入“包:google_sign_in/google_sign_in.dart”;
导入“包:firebase_auth/firebase_auth.dart”;
类GeneralTopicPage扩展StatefulWidget{
GeneralTopicPage({this.user,this.googleSignIn,this.index});
最终FirebaseUser用户;
最终谷歌签名谷歌签名;
var指数;
@凌驾
_GeneralTopicPageState createState()=>new_GeneralTopicPageState();
}
类_GeneralTopicsPageState扩展状态{
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:自定义滚动视图(
条子:[
滑杆(
对,,
标题:正文(
“测试”,
),
),
填缝料(
//很好用。
填充:所有边缘设置(16.0),
银条:银条列表(
代表:SliverChildBuilderDelegate(
(BuildContext上下文,int索引){
返回容器(
裕度:所有边缘集(20.0),
颜色:颜色,红色,
高度:400.0,
儿童:中心(
子:文本(
“这是一个用红色硬编码的普通容器,它工作得非常好。请注意,在向上滚动时没有跳过。”,
样式:TextStyle(
颜色:颜色。白色
),
textAlign:textAlign.center,
),
),
);
},
儿童人数:7,
),
),
),
填缝料(
//这就是它不能按预期工作的地方。它的行为与位于它上面和下面的容器是分开的,因为它突然包含了一个StreamBuilder。
填充:所有边缘设置(16.0),
银条:银条列表(
代表:SliverChildBuilderDelegate(
(BuildContext上下文,int索引){
返回流生成器(
流:Firestore.instance.collection(“内容”).snapshots(),
生成器:(BuildContext上下文,异步快照){
如果(!snapshot.hasData){
返回容器(
儿童:中心(
子对象:CircularProgressIndicator(),
),
);
}否则{
返回容器(
裕度:所有边缘集(20.0),
颜色:颜色。绿色,
高度:400.0,
儿童:中心(
子:文本(
snapshot.data.documents[索引]['title'],
样式:TextStyle(
颜色:颜色。白色
),
textAlign:textAlign.center,
),
),
);
}
},
);
},
儿童人数:8,
),
),
),
填缝料(
//很好用。
填充:所有边缘设置(16.0),
银条:银条列表(
代表:SliverChildBuilderDelegate(
(BuildContext上下文,int索引){
返回容器(
裕度:所有边缘集(20.0),
颜色:颜色,蓝色,
高度:400.0,
儿童:中心(
子:文本(
“这是一个普通的、用蓝色硬编码的容器,它工作得非常好。请注意在向上滚动时没有跳过。”,
样式:TextStyle(
颜色:颜色。白色
),
textAlign:textAlign.center,
),
),
);
},
儿童人数:3,
),
),
),
],
),
);
}
}