用户资料

This commit is contained in:
2022-10-26 13:24:11 +08:00
parent 69f0a7a81e
commit afee57df73
12 changed files with 368 additions and 35 deletions

View File

@@ -57,17 +57,6 @@ class _UserPageState extends State<UserPage> {
Get.toNamed(UserRoutes.setting);
},
),
const Divider(
height: 0,
color: AppColors.border,
indent: 16,
),
ActionItem(
'检查更新',
onTap: () {
Get.toNamed(UserRoutes.setting);
},
),
const Divider(
height: 0,
color: AppColors.border,

View File

@@ -2,8 +2,10 @@ import 'package:chat/configs/app_colors.dart';
import 'package:chat/routes/user_routes.dart';
import 'package:chat/services/auth_service.dart';
import 'package:chat/utils/convert.dart';
import 'package:chat/utils/ui_tools.dart';
import 'package:chat/widgets/custom_avatar.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
class UserTopBar extends StatelessWidget {
@@ -45,7 +47,32 @@ class UserTopBar extends StatelessWidget {
fontWeight: FontWeight.w400,
),
),
Text(Convert.hideCenterStr(_.userInfo.value.address ?? '')),
Row(
children: [
Text(
Convert.hideCenterStr(_.userInfo.value.address ?? ''),
style: const TextStyle(
color: AppColors.unactive,
),
),
const SizedBox(width: 4),
InkWell(
onTap: () {
Clipboard.setData(
ClipboardData(
text: _.userInfo.value.address,
),
);
UiTools.toast('地址复制成功');
},
child: const Icon(
Icons.copy,
size: 12,
color: AppColors.unactive,
),
),
],
),
],
),
Expanded(child: Container()),

View File

@@ -1,15 +0,0 @@
import 'package:flutter/material.dart';
class UserInfoAvatarPage extends StatefulWidget {
const UserInfoAvatarPage({Key? key}) : super(key: key);
@override
State<UserInfoAvatarPage> createState() => _UserInfoAvatarPageState();
}
class _UserInfoAvatarPageState extends State<UserInfoAvatarPage> {
@override
Widget build(BuildContext context) {
return Container();
}
}

View File

@@ -1,4 +1,13 @@
import 'package:chat/configs/app_colors.dart';
import 'package:chat/controllers/user_controller.dart';
import 'package:chat/routes/user_routes.dart';
import 'package:chat/services/auth_service.dart';
import 'package:chat/views/user/widgets/link_action_item.dart';
import 'package:chat/widgets/custom_circle_avatar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_cropper/image_cropper.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
class UserInfoPage extends StatefulWidget {
const UserInfoPage({Key? key}) : super(key: key);
@@ -12,8 +21,83 @@ class _UserInfoPageState extends State<UserInfoPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('用户资料'),
title: const Text('个人资料'),
),
body: GetX<AuthService>(
builder: (_) {
return SafeArea(
child: Column(
children: [
LinkActionItem(
title: '头像',
onTap: () async {
final result = await AssetPicker.pickAssets(
Get.context!,
pickerConfig: const AssetPickerConfig(
maxAssets: 1,
requestType: RequestType.image,
),
);
if (result == null) {
return;
}
_cropImage((await result.first.file)!.path);
},
trailing: CustomCircleAvatar(
_.userInfo.value.avatar,
size: 44,
borderWidth: 0.8,
borderColor: AppColors.primary,
),
),
LinkActionItem(
title: '昵称',
trailing: Text(_.userInfo.value.nickname!),
isLink: true,
onTap: () {
Get.toNamed(
UserRoutes.infoNickname,
arguments: {
'nickname': _.userInfo.value.nickname,
},
);
},
),
Expanded(child: Container()),
],
),
);
},
),
);
}
Future<void> _cropImage(String imagePath) async {
CroppedFile? croppedFile = await ImageCropper().cropImage(
sourcePath: imagePath,
maxHeight: 128,
maxWidth: 128,
compressQuality: 70,
aspectRatio: const CropAspectRatio(
ratioX: 1,
ratioY: 1,
),
compressFormat: ImageCompressFormat.png,
uiSettings: [
IOSUiSettings(
title: '头像剪裁',
doneButtonTitle: '完成',
cancelButtonTitle: '取消',
),
AndroidUiSettings(
toolbarTitle: '头像剪裁',
),
],
);
if (croppedFile != null) {
UserController.to.uploadAvatar(croppedFile.path);
}
}
}

View File

@@ -1,4 +1,7 @@
import 'package:chat/configs/app_colors.dart';
import 'package:chat/controllers/user_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class UserInfoNicknamePage extends StatefulWidget {
const UserInfoNicknamePage({Key? key}) : super(key: key);
@@ -8,8 +11,84 @@ class UserInfoNicknamePage extends StatefulWidget {
}
class _UserInfoNicknamePageState extends State<UserInfoNicknamePage> {
late TextEditingController _editingController;
late String _originNickname;
late String _nickname;
@override
void initState() {
super.initState();
_editingController = TextEditingController(text: Get.arguments['nickname']);
_nickname = Get.arguments['nickname'];
_originNickname = Get.arguments['nickname'];
}
@override
void dispose() {
_editingController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Container();
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Scaffold(
appBar: AppBar(
title: const Text(
'修改昵称',
),
actions: [
TextButton(
style: ButtonStyle(
foregroundColor: MaterialStateProperty.resolveWith((states) {
if (states.contains(MaterialState.disabled)) {
return AppColors.unactive;
} else {
return AppColors.active;
}
}),
),
onPressed: _nickname.length < 2 || _originNickname == _nickname
? null
: () async {
if (await UserController.to
.updateNickname(_editingController.text)) {
Get.back();
}
},
child: const Text(
'保存',
),
),
],
),
body: Container(
padding: const EdgeInsets.all(32.0),
child: TextField(
controller: _editingController,
onChanged: (e) {
setState(() {
_nickname = e;
});
},
decoration: const InputDecoration(
labelText: '昵称',
hintText: '请输入昵称',
labelStyle: TextStyle(
color: AppColors.unactive,
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: AppColors.unactive,
),
),
),
),
),
),
);
}
}

View File

@@ -0,0 +1,74 @@
import 'package:chat/configs/app_colors.dart';
import 'package:chat/configs/app_size.dart';
import 'package:flutter/material.dart';
class LinkActionItem extends StatelessWidget {
final IconData? prefix;
final String title;
final String? cover;
final Widget? trailing;
final bool? isLink;
final GestureTapCallback? onTap;
const LinkActionItem({
Key? key,
this.prefix,
this.cover,
required this.title,
this.isLink,
this.trailing,
this.onTap,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GestureDetector(
onTap: onTap,
child: Container(
color: AppColors.white,
padding: const EdgeInsets.symmetric(
vertical: 20,
horizontal: 16,
),
child: Row(
children: [
if (prefix != null)
Icon(
prefix,
color: AppColors.unactive,
size: 18,
),
const SizedBox(width: 8),
if (cover != null)
Image.asset(
'assets/user/$cover.png',
width: 24,
height: 24,
),
const SizedBox(width: 8),
Expanded(
child: Text(
title,
style: const TextStyle(
fontSize: 15,
),
),
),
if (trailing != null) trailing!,
if (isLink == true)
const Icon(
Icons.chevron_right,
color: AppColors.unactive,
),
],
),
),
),
const Divider(height: AppSize.dividerHeight),
],
);
}
}