diff --git a/lib/const/api.dart b/lib/const/api.dart index da8ab70..c265018 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -33,6 +33,9 @@ class _User { ///个人资料:获取用户信息 String get info => '/user/personalData/getUserDetail'; + + ///个人资料:修改管家用户昵称 + String get updateNickName => '/user/personalData/updateNickName'; } class _Manage { diff --git a/lib/ui/settings/nick_name_change_page.dart b/lib/ui/settings/nick_name_change_page.dart index afe38c1..f2c95df 100644 --- a/lib/ui/settings/nick_name_change_page.dart +++ b/lib/ui/settings/nick_name_change_page.dart @@ -1,6 +1,12 @@ +import 'package:aku_community_manager/const/api.dart'; +import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; +import 'package:aku_community_manager/utils/network/base_model.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -27,6 +33,7 @@ class _NickNameChangePageState extends State { @override Widget build(BuildContext context) { + UserProvider userProvider = Provider.of(context); return AkuScaffold( title: '修改昵称', body: Material( @@ -42,7 +49,7 @@ class _NickNameChangePageState extends State { controller: _textEditingController, decoration: InputDecoration( contentPadding: EdgeInsets.zero, - hintText: '', + hintText: '${userProvider.infoModel.nickName}', hintStyle: TextStyle(color: Color(0xFF999999), fontSize: 34.sp), border: UnderlineInputBorder( @@ -54,9 +61,17 @@ class _NickNameChangePageState extends State { ), 150.w.heightBox, MaterialButton( - onPressed: () { - // userProvider.setName(_textEditingController.text); - Get.back(); + onPressed: () async { + BaseModel baseModel = await NetUtil().post( + API.user.updateNickName, + params: {'nickName': _textEditingController.text}); + + if (baseModel.status == true) { + userProvider.setNickName(_textEditingController.text); + Get.back(); + } else { + BotToast.showText(text: baseModel.message); + } }, child: '保存'.text.black.size(32.sp).make(), color: Color(0xFFFFC40C), diff --git a/lib/ui/settings/user_info_page.dart b/lib/ui/settings/user_info_page.dart index deaf2ba..53838aa 100644 --- a/lib/ui/settings/user_info_page.dart +++ b/lib/ui/settings/user_info_page.dart @@ -1,5 +1,6 @@ // Flutter imports: import 'package:aku_community_manager/tools/aku_divider.dart'; +import 'package:aku_community_manager/ui/settings/nick_name_change_page.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -14,6 +15,7 @@ import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_tile.dart'; import 'package:aku_community_manager/ui/widgets/inner/pick_image.dart'; import 'package:aku_community_manager/tools/extensions/list_extension_tool.dart'; +import 'package:aku_community_manager/tools/extensions/router_extension_tool.dart'; class UserInfoPage extends StatefulWidget { UserInfoPage({Key key}) : super(key: key); @@ -42,7 +44,10 @@ class _UserInfoPageState extends State { suffix: AkuAvatar(), ), AkuTile( - onTap: () {}, + onTap: () async { + await NickNameChangePage().to(); + setState(() {}); + }, title: Text('昵称'), suffix: Text(userProvider.infoModel.nickName), ),