gpt4 book ai didi

flutter - “The method '其中带firestore flutter的streambuilder时的' was called on null.”

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

我正在使用StreamBuilder从Firestore流一些数据。

它工作正常,并且正在显示数据,但控制台中存在错误。

我认为这可能是包含错误的代码:

Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Consumer<AppState>(
builder: (context, appState, _) =>
StreamBuilder<List<Dentist>>(
stream: database.dentistsStream(),
builder: (context, snapshot) => Column(
children: <Widget>[
for (final dentist in snapshot.data.where((e) => e
.categoryIds
.contains(appState.selectedCategoryId)))
GestureDetector(
onTap: () {},
child: DentistItem(
dentist: dentist,
),
),
],
),
),
),
),

和错误:

enter image description here

有帮助吗?

注意:我知道Dart的旧版本不支持此处的“for”。

最佳答案

在根据快照创建列之前,请确保快照具有数据if (snapshot.hasData)

Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Consumer<AppState>(
builder: (context, appState, _) => StreamBuilder<List<Dentist>>(
stream: database.dentistsStream(),
builder: (context, snapshot) {
if (snapshot.hasData)
return Column(
children: <Widget>[
for (final dentist in snapshot.data.where((e) =>
e.categoryIds.contains(appState.selectedCategoryId)))
GestureDetector(
onTap: () {},
child: DentistItem(
dentist: dentist,
),
),
],
);
return Center(child: CircularProgressIndicator());
},
),
),
)

关于flutter - “The method '其中带firestore flutter的streambuilder时的' was called on null.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61398262/

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