【发布时间】:2020-04-06 16:39:05
【问题描述】:
我开发了一个管理应用程序,其中我有登录页面,该页面指向我的仪表板,我可以选择注销,但我不能这样做。
这是我的代码:
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Row(
children: <Widget>[
Expanded(
child: FlatButton.icon(
onPressed: () {
setState(() => _selectedPage = Page.dashboard);
},
icon: Icon(
Icons.dashboard,
color: _selectedPage == Page.dashboard
? active
: notActive,
),
label: Text('Dashboard'))),
Expanded(
child: FlatButton.icon(
onPressed: () {
setState(() => _selectedPage = Page.manage);
},
icon: Icon(
Icons.sort,
color:
_selectedPage == Page.manage ? active : notActive,
),
label: Text('Manage'))),
],
),
elevation: 0.0,
backgroundColor: Colors.white,
),
body: _loadScreen());
}
Widget _loadScreen() {
switch (_selectedPage) {
case Page.dashboard:
return FutureBuilder(
future: getUsersCount(),
builder: (BuildContext context, AsyncSnapshot<String> text) {
print(text);
if(text== "-1"){
return CircularProgressIndicator();
} else {
return Column(
children: <Widget>[
ListTile(
subtitle: Text('Admin View', textAlign: TextAlign.center,
style: TextStyle(fontSize: 29.0,
color: Colors.indigo,
fontWeight: FontWeight.bold),),
),
Expanded(child: GridView(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,),
children: <Widget>[
Padding(padding: const EdgeInsets.all(18.0),
child: Card(child: ListTile(
title: FlatButton.icon(
onPressed: null,
icon: Icon(
Icons.people, color: Colors.black,),
label: Text("Users", style: TextStyle(
fontSize: 9, color: Colors.indigo),)),
subtitle: Text(text.data != null ? text.data : '',
textAlign: TextAlign.center,
style: TextStyle(color: active, fontSize: 50.0),
)),
),
),
],
),
),
],
);
}
});
break;
case Page.manage:
return ListView(
children: <Widget>[
ListTile(
leading: Icon(Icons.lock,color: Colors.black,),
title: Text("Logout",style: TextStyle(color: Colors.indigo),),
onTap: () {
Navigator.push(context, MaterialPageRoute(builder: (context)=> AdminLogin()));
// _brandAlert();
},
),
Divider(),
],
);
break;
default:
return Container();
}
}
void _categoryAlert() {
var alert = new AlertDialog(
content: Form(
key: _categoryFormKey,
child: TextFormField(
controller: categoryController,
validator: (value){
if(value.isEmpty){
return 'category cannot be empty';
}
return null;
},
decoration: InputDecoration(
hintText: "add Promocode",
),
),
),
actions: <Widget>[
FlatButton(onPressed: (){
if(categoryController.text != null){
_categoryService.createCategory(categoryController.text);
}
Fluttertoast.showToast(msg: 'Promocode changed');
Navigator.pop(context);
}, child: Text('ADD')),
FlatButton(onPressed: (){
Navigator.pop(context);
}, child: Text('CANCEL')),
],
);
showDialog(context: context, builder: (_) => alert);
}
}
我希望退出管理仪表板,然后再次切换到我的登录页面。
【问题讨论】:
-
与其推路由,不如
pushAndRemoveUntil。但无论如何,从应用程序注销还不够,您要处理的方式取决于您如何管理数据和身份验证以及如何跟踪经过身份验证的用户。
标签: firebase flutter dart firebase-authentication