【发布时间】:2019-08-28 08:41:58
【问题描述】:
我正在为我的应用程序使用 FirebaseAuth 和 Firestore。
'User' 是一个模型,它代表 Firestore 上的文档,并使用 FirebaseUser 的 uid 作为其 DocumentId。
为了获得“用户”,我必须从 FirebaseUser 传入 uid。
我的想法是先设置一个FirebaseUser的StreamProvider,然后再设置一个User的StreamProvider,以FirebaseUser为参数。
但是发生了错误,我找不到这个问题的解决方案,任何建议都会对我很有帮助。
List<SingleChildCloneableWidget> uiConsumableProviders = [
StreamProvider<FirebaseUser>(
builder: (context) => Provider.of<LoginNotifier>(context, listen: false).streamFirebaseUser,
),
StreamProvider<User>(
builder: (context) =>
Provider.of<UserNotifier>(context, listen: false).streamUser(Provider.of<FirebaseUser>(context)),
),
];
I/flutter (15813): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (15813): The following assertion was thrown building InheritedProvider<FirebaseUser>:
I/flutter (15813): inheritFromWidgetOfExactType(InheritedProvider<FirebaseUser>) or inheritFromElement() was called
I/flutter (15813): before BuilderStateDelegate<Stream<User>>.initDelegate() completed.
I/flutter (15813):
I/flutter (15813): When an inherited widget changes, for example if the value of Theme.of()
I/flutter (15813): changes, its dependent widgets are rebuilt. If the dependent widget's reference
I/flutter (15813): to the inherited widget is in a constructor or an initDelegate() method, then
I/flutter (15813): the rebuilt dependent widget will not reflect the changes in the inherited
I/flutter (15813): widget.
I/flutter (15813):
I/flutter (15813): Typically references to inherited widgets should occur in widget build()
I/flutter (15813): methods. Alternatively, initialization based on inherited widgets can be placed
I/flutter (15813): in the didChangeDependencies method, which is called after initDelegate and
I/flutter (15813): whenever the dependencies change thereafter.
I/flutter (15813):
【问题讨论】:
-
还不支持。尚不清楚它的行为方式,因为
builder仅被调用一次,但从另一个提供程序获得的值会随着时间而改变。 -
@RémiRousselet 是的,这正是我被卡住的原因。我的目的是我想从小部件树中的任何地方获取用户数据,所以我需要像流一样的东西。请你给我一些关于这个问题的建议吗?