gpt4 book ai didi

firebase - flutter 错误 : type 'StreamBuilder' is not a subtype of type 'String'

转载 作者:行者123 更新时间:2023-12-03 04:20:23 24 4
gpt4 key购买 nike

我想显示 Firestore 数据中卡片的颜色。但我收到以下错误。
数据“颜色”在 Firestore 中存储为字符串,然后转换为 int。
让我知道我该如何处理这个错误。
enter image description here
这是我显示错误的代码:

@override
void initState() {
super.initState();
checkIfColorOrNot();
}

bool selectedColor = false;

checkIfColorOrNot() async {
DocumentSnapshot ds = await Firestore.instance
.collection('rackBookItems')
.document(widget.rackBookItems.id)
.collection('user')
.document(widget.user.uid)
.get();
this.setState(() {
selectedColor = ds.exists;
});
}

_colorSelected() {
return StreamBuilder(
stream: selectedColor
? Firestore.instance
.collection('rackBookItems')
.document(widget.rackBookItems.id)
.collection('user')
.document(widget.user.uid)
.snapshots()
: Firestore.instance
.collection('rackBookItems')
.document(widget.rackBookItems.id)
.snapshots(),
builder: (context, snapshot) {
//checking the snapshot.data is not null before you call snapshot.data.documents.
if (!snapshot.hasData) return CircularProgressIndicator();
var userDocument = snapshot.data;
return userDocument['color'];
},
);
}

@override
Widget build(BuildContext context) {
final length = MediaQuery.of(context).size;
return InkWell(
onTap: widget.onTap,
child: Card(
color: Color(int.parse(_colorSelected())),
elevation: 5,))}

最佳答案

你应该使用类似的东西:

_colorSelected(){

var document = await Firestore.instance.collection('rackBookItems').document('user').get();
return document.data['color'];
}
也许还要检查颜色是否存在!

关于firebase - flutter 错误 : type 'StreamBuilder<DocumentSnapshot>' is not a subtype of type 'String' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62997238/

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