late List<Map<String, dynamic>> items;
bool isLoaded = false;
var collection =
FirebaseFirestore.instance.collection("ClientStores").snapshots();
getStoresSubscribed() async {
try {
if (idCurrentSession != "" && usrClient == true) {
List<Map<String, dynamic>> tempList = [];
await for (var StoreSubscribedSnap in collection) {
for (var StoreSubscribedDocs in StoreSubscribedSnap .docs) {
if (StoreSubscribedDocs["StoreID"] != null) {
String idStore = StoreSubscribedDocs["StoreID"];
var collection2 = FirebaseFirestore.instance
.collection("ClientStores")
.doc(idStore)
.collection("Clients");
var docSnapshot = await collection2.doc(idCurrentSession).get();
if (docSnapshot.exists) {
Map<String, dynamic>? data = docSnapshot.data();
String clientIdStore = data?['StoreID'];
var dataStore = await FirebaseFirestore.instance
.collection("Stores")
.where("StoreID", isEqualTo: clientIdStore)
.get();
for (var element in dataStore.docs) {
tempList.add(element.data());
}
setState(() {
items = tempList;
isLoaded = true;
});
}
}
}
}
}
} catch (e) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
backgroundColor: Colors.orangeAccent,
content: Text(
"$e",
style: TextStyle(fontSize: 18.0),
)));
}
}
@override
void initState() {
super.initState();
getStoresSubscribed();
}
这就是我在应用程序栏中使用backtton返回主页的方式:
leading: BackButton( onPressed: () { Navigator.of(context).pop(); },
这是我在主页上的签名按钮上调用的功能:
Future<void> signout({required BuildContext context}) async {
await FirebaseAuth.instance.signOut();
await Future.delayed(const Duration(seconds: 1));
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => const HomeScreen()));
}
我试图使用(安装),就像我在许多答案中所读到的那样(安装),但我仍然会遇到错误。 Maybe我在这部分上错误地使用了国家或我缺少某些东西?任何帮助将不胜感激。
谢谢你
如果您遇到了窗口小部件已卸载的错误,则意味着小部件的上下文不再在小部件树中。您可以在调用
pushReplacement
之前检查小部件是否已安装。
Future<void> signout({required BuildContext context}) async {
await FirebaseAuth.instance.signOut();
await Future.delayed(const Duration(seconds: 1));
if(context.mounted) {
Navigator.pushReplacement(
context,
MaterialPageRoute(
builder: (BuildContext context) => const HomeScreen()));
}
}
检查有关
mounted
如果在异步差距(即执行异步操作后)使用buildContext,请考虑检查已安装的以确定上下文在与之交互之前是否仍然有效:
https://api.flutter.dev/flutter/widgets/buildcontext/mounted.html