1
This commit is contained in:
@@ -1,7 +1,14 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:plan/api/dto/login_dto.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:remixicon/remixicon.dart';
|
||||
|
||||
import '../../api/endpoints/user_api.dart';
|
||||
import '../../providers/app_store.dart';
|
||||
import '../../router/config/route_paths.dart';
|
||||
import 'widget/avatar_name.dart';
|
||||
import 'widget/profile_section.dart';
|
||||
|
||||
@@ -15,6 +22,72 @@ class MyPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyPageState extends State<MyPage> {
|
||||
|
||||
///退出登陆
|
||||
void _handLogout() async {
|
||||
await showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (_) => CupertinoAlertDialog(
|
||||
title: Text("Log Out?"),
|
||||
content: Text("Are you sure you want to log out? You’ll need to sign in again to access your account."),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text("Cancel"),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text("Log Out"),
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
var appStore = context.read<AppStore>();
|
||||
appStore.logout();
|
||||
context.go(RoutePaths.login);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///注销账号
|
||||
void _handDelete() async {
|
||||
await showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (_) => CupertinoAlertDialog(
|
||||
title: Text("Delete Account?"),
|
||||
content: Text("Are you sure you want to delete your account? You won’t be able to recover your account."),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
onPressed: () {
|
||||
context.pop();
|
||||
},
|
||||
child: Text("Cancel"),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: Text("Delete"),
|
||||
onPressed: () async {
|
||||
context.pop();
|
||||
EasyLoading.show();
|
||||
await deleteAccountApi();
|
||||
EasyLoading.dismiss();
|
||||
var appStore = context.read<AppStore>();
|
||||
appStore.logout();
|
||||
context.go(RoutePaths.login);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
///编辑资料
|
||||
void _updateUserInfo(UserInfo value) {
|
||||
var appStore = context.read<AppStore>();
|
||||
appStore.updateUserInfo(value);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoPageScaffold(
|
||||
@@ -32,8 +105,31 @@ class _MyPageState extends State<MyPage> {
|
||||
child: ListView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
|
||||
children: [
|
||||
AvatarName(),
|
||||
ProfileSection(),
|
||||
AvatarName(
|
||||
onUpdate: _updateUserInfo,
|
||||
),
|
||||
ProfileSection(
|
||||
onUpdate: _updateUserInfo,
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.only(top: 50),
|
||||
child: CupertinoButton(
|
||||
color: CupertinoColors.systemRed,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
onPressed: _handLogout,
|
||||
child: Text(
|
||||
"退出登录",
|
||||
style: TextStyle(color: Colors.white, fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
CupertinoButton(
|
||||
onPressed: _handDelete,
|
||||
child: const Text(
|
||||
"删除账号",
|
||||
style: TextStyle(color: CupertinoColors.systemRed, fontSize: 14),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user