gpt4 book ai didi

firebase - 无法从数据库获取DataSnapshot并获取空值

转载 作者:行者123 更新时间:2023-12-03 04:18:31 25 4
gpt4 key购买 nike

我试图通过按用户的故事按钮来查看用户故事,将我导航到整页的StoryView以查看图像。我认为我无法将数据传递到下一页或从数据库查询数据。我不确定哪里出了问题。
这是我得到的错误:

The following _TypeError was thrown building Builder:type '(DataSnapshot) => Null' is not a subtype of type '(dynamic) => dynamic' of 'f''


这是我在要查看图像的实际页面上调用要检索的数据的地方。错误指向crudMethods.getStoryListData()行
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:flutter/material.dart';
import 'package:link_me/services/crud.dart';
import "package:story_view/story_view.dart";

class StoryPageView extends StatefulWidget {
final String currentUser;
final String storyUrl;

StoryPageView({this.currentUser, this.storyUrl});

@override
_StoryPageViewState createState() => _StoryPageViewState();
}

class _StoryPageViewState extends State<StoryPageView> {
CrudMethods crudMethods = new CrudMethods();
List<String> itemList = new List();
final StoryController controller = StoryController();


QuerySnapshot storySnapshot;

@override
void initState() {
super.initState();
CrudMethods crudMethods = new CrudMethods();

crudMethods.getStoryListData().then((DataSnapshot snapshot) {
//storySnapshot = result;
var urlData = snapshot.value;
//itemList.clear();
urlData.forEach((key, value) {
itemList.add(value['storyUrl']);
});

setState(() {
print(itemList.length);
});
});
}

loadStory() {
return ListView(
children: <Widget>[
itemList == null ? CircularProgressIndicator()
: Container(
child: StoryView(
storyItems: [
for (var i in itemList) show(i)
],
controller: controller,
progressPosition: ProgressPosition.top,
repeat: false,
),
),
],
);
}

show(String urlData) {
return StoryItem.pageImage(
url: urlData,
controller: controller,
);
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
margin: EdgeInsets.all(8.0),
child: Column(
children:<Widget>[
Padding(
padding: EdgeInsets.fromLTRB(0, 5, 5, 5),
child: Container(
height: MediaQuery.of(context).size.width,
width: MediaQuery.of(context).size.height,
child: loadStory(),
),
),
],
),
),
);
}
}
这就是我从主故事列表页面导航到该页面的方式,该页面显示了发布新故事的所有用户
onTap: () => Navigator.push(context,
MaterialPageRoute(builder: (context) => StoryPageView(currentUser: currentUser.id,))),
这是从我用来调用数据的实用程序文件中获得的
getStoryListData() async {
return storyPostReference.document(currentUser.id).collection("storyPostItems").orderBy("timestamp", descending: true).snapshots();
}

最佳答案

您正在UI中使用Future,但是从getStoryListData()返回流,因此您必须以
future 的getStoryListData()异步{
Querysnapshot快照= storyPostReference.document(currentUser.id).collection(“storyPostItems”)。orderBy(“timestamp”,降序:true)。得到();
返回快照;

关于firebase - 无法从数据库获取DataSnapshot并获取空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63963923/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com