英文:
'Stream<DocumentSnapshot<Map<String, dynamic>>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?'
问题
I wanted to use DropdownMenu and display data from my 'reports' collection in it.
But I get an error "The argument type 'Stream<DocumentSnapshot<Map<String, dynamic>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?"
My code:
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('reports')
.doc(userID)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
const CircularProgressIndicator();
} else {
final currencyItems = <DropdownMenuItem>[];
for (var i = 0; i < snapshot.data!.docs.length; i++) {
final DocumentSnapshot snap = snapshot.data!.docs[i];
currencyItems.add(
DropdownMenuItem(
value: snap.id,
child: Text(
snap.id,
style: const TextStyle(color: Color(0xff11b719)),
),
),
);
}
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Icon(Icons.abc, size: 25, color: Color(0xff11b719)),
const SizedBox(width: 50.0),
DropdownButton(
items: currencyItems,
onChanged: (currencyValue) {
setState(() {
final selectedCurrency = currencyValue;
});
},
isExpanded: false,
hint: new Text(
"Choose Currency Type",
style: TextStyle(color: Color(0xff11b719)),
),
),
],
);
}
return Container();
},
)
Does anyone have any advice? Thank you!
英文:
I wanted to use DropdownMenu and display data from my 'reports' collection in it.
But I get an error "The argument type 'Stream<DocumentSnapshot<Map<String, dynamic>>' can't be assigned to the parameter type 'Stream<QuerySnapshot<Object?>>?"
My code:
StreamBuilder<QuerySnapshot>(
stream: FirebaseFirestore.instance
.collection('reports')
.doc(userID)
.snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
const CircularProgressIndicator();
} else {
final currencyItems = <DropdownMenuItem>[];
for (var i = 0; i < snapshot.data!.docs.length; i++) {
final DocumentSnapshot snap = snapshot.data!.docs[i];
currencyItems.add(
DropdownMenuItem(
value: snap.id,
child: Text(
snap.id,
style: const TextStyle(color: Color(0xff11b719)),
),
),
);
}
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Icon(Icons.abc, size: 25, color: Color(0xff11b719)),
const SizedBox(width: 50.0),
DropdownButton(
items: currencyItems,
onChanged: (currencyValue) {
setState(() {
final selectedCurrency = currencyValue;
});
},
// value: selectedCurrency,
isExpanded: false,
hint: new Text(
"Choose Currency Type",
style: TextStyle(color: Color(0xff11b719)),
),
),
],
);
}
return Container();
},
),
Does anyone have any advice ? Thank you !
答案1
得分: 1
你可以在streamBuilder上更改dateType,就像它所示的那样。
英文:
You can change the dateType on streamBuilder as it showed.
StreamBuilder<DocumentSnapshot<Map<String, dynamic>>>(
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论