我在使用 Provider 包通过 SnackBar 显示消息时遇到问题。我得到的错误信息是:
VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable.
To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
#0 Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3508:9)
#1 Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3522:6)
#2 Element.findAncestorStateOfType (package:flutter/src/widgets/framework.dart:3641:12)
#3 Scaffold.of (package:flutter/src/material/scaffold.dart:1313:42)
#4 LoginScreen.build.<anonymous closure>.<anonymous closure> (package:zvjs_app/screens/login_screen.dart:74:38)
<asynchronous suspension>
#5 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182<…>
Run Code Online (Sandbox Code Playgroud)
Bellow 是我的代码,我认为所有属于所需逻辑的类。我不明白为什么 …
我使用 Firebase 作为 Flutter 项目的后端。我需要在一个事务中写入多个表。我现在有:
await _databaseReference
.collection('user_data')
.document(uid)
.setData(userData);
await _databaseReference
.collection('company_data')
.document(uid)
.setData(companyData);
Run Code Online (Sandbox Code Playgroud)
但这是 2 笔交易,因此 1 笔交易可能会成功结束,但另一笔交易可能会失败,我想防止发生这种情况。
多谢。
firebase google-cloud-platform firebase-realtime-database flutter google-cloud-firestore