This commit is contained in:
zhutao
2025-09-04 17:57:35 +08:00
parent 4d12f8afc2
commit 0231dcfe1a
34 changed files with 1339 additions and 368 deletions

View File

@@ -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? Youll 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 wont 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),
),
),
],
),
),

View File

@@ -1,8 +1,18 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_image_compress/flutter_image_compress.dart';
import 'package:plan/api/dto/login_dto.dart';
import 'package:plan/api/endpoints/user_api.dart';
import 'package:plan/providers/app_store.dart';
import 'package:plan/utils/common.dart';
import 'package:provider/provider.dart';
import 'package:remixicon/remixicon.dart';
import 'package:file_picker/file_picker.dart';
class AvatarName extends StatefulWidget {
const AvatarName({super.key});
final Function(UserInfo) onUpdate;
const AvatarName({super.key, required this.onUpdate});
@override
State<AvatarName> createState() => _AvatarNameState();
@@ -19,94 +29,150 @@ class _AvatarNameState extends State<AvatarName> {
setState(() {
_isEdit = true;
});
AppStore appStore = context.read<AppStore>();
WidgetsBinding.instance.addPostFrameCallback((_) {
_inputController.text = appStore.userInfo?.name ?? "";
_focusNode.requestFocus();
});
}
///确定编辑内容
void _confirmEdit(String value) {
///确定编辑名字
void _confirmEdit(String value) async {
setState(() {
_isEdit = false;
});
var res = await updateUserInfoApi(name: value);
widget.onUpdate(res);
}
///选择图片
void _handPickImage() async {
var result = await FilePicker.platform.pickFiles(
type: FileType.image,
allowMultiple: false,
);
if (result != null) {
//压缩文件
final compress = await FlutterImageCompress.compressWithFile(
result.files[0].path!,
minWidth: 500,
minHeight: 500,
quality: 85,
rotate: 0,
);
var res = await updateUserInfoApi(avatar: compress);
widget.onUpdate(res);
}
}
@override
Widget build(BuildContext context) {
return Row(
spacing: 15,
children: [
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
color: Color(0xffcae2fd),
border: Border.all(
color: Color(0xff797e80),
width: 2,
),
borderRadius: BorderRadius.circular(5),
),
alignment: Alignment.center,
child: Container(
width: 50,
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Color(0xff8e8d93),
borderRadius: BorderRadius.circular(5),
),
child: Icon(
RemixIcons.user_fill,
color: Color(0xffcae2fd),
),
),
),
Expanded(
child: Visibility(
visible: _isEdit,
replacement: InkWell(
onTap: _handleEdit,
child: Row(
spacing: 10,
children: [
Text(
"教练如何称呼你?",
style: Theme.of(context).textTheme.labelMedium,
),
Icon(
RemixIcons.pencil_fill,
size: 18,
color: Theme.of(context).textTheme.labelMedium?.color,
),
],
),
),
child: TextField(
focusNode: _focusNode,
controller: _inputController,
style: TextStyle(fontSize: 14),
decoration: InputDecoration(
hintText: "输入你的姓名",
isCollapsed: true,
contentPadding: EdgeInsets.symmetric(vertical: 8, horizontal: 10),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color: Theme.of(context).colorScheme.surfaceContainerHigh,
return Consumer<AppStore>(
builder: (context, store, __) {
return Row(
spacing: 15,
children: [
InkWell(
onTap: _handPickImage,
child: Container(
width: 80,
height: 80,
decoration: BoxDecoration(
color: Color(0xffcae2fd),
border: Border.all(
color: Color(0xff797e80),
width: 2,
),
borderRadius: BorderRadius.circular(5),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color: Theme.of(context).colorScheme.surfaceContainerHigh,
alignment: Alignment.center,
child: Visibility(
visible: getNotEmpty(store.userInfo?.avatar) == null,
replacement: CachedNetworkImage(
width: double.infinity,
height: double.infinity,
fit: BoxFit.cover,
imageUrl: store.userInfo?.avatar ?? "",
errorWidget: (context, url, error) => Icon(Icons.error),
placeholder: (context, url) => Container(
width: 30,
height: 30,
alignment: Alignment.center,
child: CircularProgressIndicator(),
),
),
child: Container(
width: 50,
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Color(0xff8e8d93),
borderRadius: BorderRadius.circular(5),
),
child: Icon(
RemixIcons.user_fill,
color: Color(0xffcae2fd),
),
),
),
),
onSubmitted: _confirmEdit,
),
),
),
],
Expanded(
child: Visibility(
visible: _isEdit,
replacement: InkWell(
onTap: _handleEdit,
child: Row(
spacing: 10,
children: [
Visibility(
visible: getNotEmpty(store.userInfo?.name) == null,
replacement: Text(
store.userInfo?.name ?? "",
style: Theme.of(context).textTheme.titleSmall,
),
child: Text(
"教练如何称呼你?",
style: Theme.of(context).textTheme.labelMedium,
),
),
Icon(
RemixIcons.pencil_fill,
size: 18,
color: Theme.of(context).textTheme.labelMedium?.color,
),
],
),
),
child: TextField(
focusNode: _focusNode,
controller: _inputController,
style: TextStyle(fontSize: 14),
maxLength: 20,
decoration: InputDecoration(
hintText: "输入你的姓名",
isCollapsed: true,
contentPadding: EdgeInsets.symmetric(vertical: 8, horizontal: 10),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color: Theme.of(context).colorScheme.surfaceContainerHigh,
),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color: Theme.of(context).colorScheme.surfaceContainerHigh,
),
),
),
onSubmitted: _confirmEdit,
),
),
),
],
);
},
);
}
}

View File

@@ -1,8 +1,15 @@
import 'package:flutter/material.dart';
import 'package:plan/api/dto/login_dto.dart';
import 'package:plan/api/endpoints/user_api.dart';
import 'package:plan/providers/app_store.dart';
import 'package:plan/utils/debouncer.dart';
import 'package:provider/provider.dart';
import 'package:remixicon/remixicon.dart';
class ProfileSection extends StatefulWidget {
const ProfileSection({super.key});
final Function(UserInfo) onUpdate;
const ProfileSection({super.key, required this.onUpdate});
@override
State<ProfileSection> createState() => _ProfileSectionState();
@@ -12,7 +19,35 @@ class _ProfileSectionState extends State<ProfileSection> {
//输入框
final TextEditingController _inputController = TextEditingController();
final List<String> _tips = ["教练每次为你制定计划时,都会首先参考这里的信息", "你分享的背景信息越详细,教练就越能为你量身定制,符合你独特情况的行动步骤", "你可以在这里为教练提需求,比如“我不吃香菜”"];
final List<String> _tips = [
"教练每次为你制定计划时,都会首先参考这里的信息",
"你分享的背景信息越详细,教练就越能为你量身定制,符合你独特情况的行动步骤",
"你可以在这里为教练提需求,比如“我不吃香菜”",
];
//防抖
Debouncer debouncer = Debouncer(milliseconds: 2000);
@override
void initState() {
super.initState();
AppStore appStore = context.read<AppStore>();
_inputController.text = appStore.userInfo?.description ?? "";
}
@override
void dispose() {
super.dispose();
debouncer.dispose();
}
///确定编辑画像
void _onTextChanged(String value) {
debouncer.run(() async {
var res = await updateUserInfoApi(description: value);
widget.onUpdate(res);
});
}
@override
Widget build(BuildContext context) {
@@ -38,9 +73,10 @@ class _ProfileSectionState extends State<ProfileSection> {
margin: EdgeInsets.only(bottom: 20),
child: TextField(
maxLines: 5,
maxLength: 200,
maxLength: 500,
controller: _inputController,
style: TextStyle(fontSize: 14, letterSpacing: 1),
onChanged: _onTextChanged,
decoration: InputDecoration(
hintText: "我是19岁女生,刷碗时用洗碗机,请不要按手洗拆解步骤..",
enabledBorder: OutlineInputBorder(