gpt4 book ai didi

firebase - 错误 : _elements. 包含(元素)不正确

转载 作者:行者123 更新时间:2023-12-03 03:41:04 24 4
gpt4 key购买 nike

我正在使用 Firebase Auth仅适用于 邮箱和密码 .登录应用程序,抽屉工作正常,但再次打开应用程序,(我使用静默登录 - 或自动登录 - 使用 Firebase 方法 currentUser )当我点击抽屉项目时,第二页打开没有错误,但是当我回到主页时,应用程序会引发此错误:

【APP】: https://scontent.fbau1-1.fna.fbcdn.net/v/t1.0-9/57251227_2177328588988443_6958567508873838592_n.jpg?_nc_cat=110&_nc_ht=scontent.fbau1-1.fna&oh=c2d1d1ade45868bec6e691ca59ab0f16&oe=5D696DE3


[调试控制台]: https://scontent.fbau1-1.fna.fbcdn.net/v/t1.0-9/58374272_2177338388987463_5540408808548859904_o.jpg?_nc_cat=111&_nc_ht=scontent.fbau1-1.fna&oh=3825f264dadd1df0005be42a59d07cb5&oe=5D71762D


main.dart

home: FutureBuilder<FirebaseUser>(
future: _auth.getCurrentUser(),
builder: (context, snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.none:
case ConnectionState.waiting:
return Container(
child: Loading.load,
color: Colors.white,
);
default:
if (snapshot.hasError)
return Text('Erro: ${snapshot.error}');
else if (snapshot.data == null)
return PageLogin(
auth: Auth(),
);
else
return PageHome();
}
},
));


auth.dart
class Auth implements BaseAuth {
final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
static FirebaseUser _user;

Future<FirebaseUser> getCurrentUser() async {
if (_user == null) {
_user = await _firebaseAuth.currentUser();
}

await loadUserAccess();

return _user;
}

}


page_home.dart
class PageHome extends StatelessWidget {
final _scaffoldKey = new GlobalKey<ScaffoldState>();
final Auth auth = Auth();

@override
Widget build(BuildContext context) {
return FutureBuilder<bool>(
future: _loadConnections(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return Container(
child: Loading.load,
color: Colors.white,
);
} else {
return Scaffold(
key: _scaffoldKey,
drawer: Drawer(
child: ListView(
padding: EdgeInsets.zero,
children: _drawerListItens(context))),
appBar: AppBar(
title: Text("Title"),
body: Container(),
);
}
},
);
}

Future<bool> _loadConnections() async {
try {
if (FirebaseUtil.fbRef() == null) {
await FirebaseUtil.loadReference();
}

//SQLite reference
await DBProvider.db.database;

if (!auth.userIsAdmin()) {
//check if user is admin
await auth.loadUserAccess();
}
return true;
} catch (e) {
return false;
}
}



List<Widget> _drawerListItens(context) {
List<Widget> _drawerItens = List<Widget>();

_drawerItens.addAll([
ListTile(
title: Text("Second Page"),
onTap: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
SecondPage(String someData)));
},
),
]);

return _drawerItens;

}



}

最佳答案

重复的键可能会导致此错误。在我的应用程序中,它是 Scaffold 的 key导致此错误。
如果您为 Scaffold 和 AppBar 使用基类,则从调用基类的类中传递 key 。例如

Class BaseScaffold{
final GlobalKey<ScaffoldState> _scaffoldKey;
BaseScaffold(this._scaffoldKey);
Widget build(BuildContext context) {
return Scaffold(

key : _scaffoldKey
...
);
}
}

Class B extends StatelessWidget{
final _scaffoldKey = GlobalKey<ScaffoldState>();
Widget build(BuildContext context) {
return BaseScaffold(
key: _scaffoldKey
...
);
}
}

关于firebase - 错误 : _elements. 包含(元素)不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55911525/

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