feat: 實作登出
點擊登出按鈕後刪除share preference 資料及跳轉回登入畫面
This commit is contained in:
parent
b0ef478e99
commit
a07d69f1ab
|
|
@ -1,5 +1,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:topic/BottomNavBar.dart';
|
import 'package:topic/BottomNavBar.dart';
|
||||||
import 'package:topic/main.dart';
|
import 'package:topic/main.dart';
|
||||||
import 'package:topic/HomePage.dart';
|
import 'package:topic/HomePage.dart';
|
||||||
|
|
@ -109,6 +111,19 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _loginOut() async {
|
||||||
|
SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
|
// remove all data in share preference(user data which save to identify user or others)
|
||||||
|
prefs.clear();
|
||||||
|
// navbar router setting
|
||||||
|
// replace screen with LoginPage and without navbar
|
||||||
|
pushReplacementWithoutNavBar(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => LoginPage(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
//頁面
|
//頁面
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
@ -208,7 +223,9 @@ class _PersonalInfoState extends State<PersonalInfo> {
|
||||||
width: 60,
|
width: 60,
|
||||||
),
|
),
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
onPressed: () {},
|
onPressed: () {
|
||||||
|
_loginOut();
|
||||||
|
},
|
||||||
child: Text('登出'),
|
child: Text('登出'),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
backgroundColor: Color(0xFFF5E3C3),
|
backgroundColor: Color(0xFFF5E3C3),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user