139 lines
4.0 KiB
Dart
139 lines
4.0 KiB
Dart
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';
|
||
|
||
class MyPage extends StatefulWidget {
|
||
final GlobalKey<ScaffoldState> scaffoldKey;
|
||
|
||
const MyPage({super.key, required this.scaffoldKey});
|
||
|
||
@override
|
||
State<MyPage> createState() => _MyPageState();
|
||
}
|
||
|
||
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(
|
||
backgroundColor: Colors.white,
|
||
navigationBar: CupertinoNavigationBar(
|
||
middle: Text("Profile"),
|
||
leading: IconButton(
|
||
onPressed: () {
|
||
widget.scaffoldKey.currentState?.closeDrawer();
|
||
},
|
||
icon: Icon(RemixIcons.close_circle_line, size: 25),
|
||
),
|
||
),
|
||
child: SafeArea(
|
||
child: ListView(
|
||
padding: EdgeInsets.symmetric(horizontal: 30, vertical: 20),
|
||
children: [
|
||
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(
|
||
"Log Out",
|
||
style: TextStyle(color: Colors.white, fontSize: 14),
|
||
),
|
||
),
|
||
),
|
||
CupertinoButton(
|
||
onPressed: _handDelete,
|
||
child: const Text(
|
||
"Delete Account",
|
||
style: TextStyle(color: CupertinoColors.systemRed, fontSize: 14),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|