From 45899c8afd415171e2782b8681b090d8e6b2db03 Mon Sep 17 00:00:00 2001 From: zhang <494089941@qq.com> Date: Mon, 18 Jan 2021 18:43:04 +0800 Subject: [PATCH] add change nick name --- lib/constants/api.dart | 3 + lib/pages/personal/change_nick_name_page.dart | 84 +++++++++++++++++++ lib/pages/personal/user_profile_page.dart | 5 +- lib/provider/user_provider.dart | 10 ++- pubspec.lock | 7 -- 5 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 lib/pages/personal/change_nick_name_page.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index ab3385e7..fe7b27c8 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -35,4 +35,7 @@ class _User { ///用户退出登陆 String get logout => '/user/signOut'; + + ///修改用户昵称 + String get updateNickName =>'/user/personalData/updateNickName'; } diff --git a/lib/pages/personal/change_nick_name_page.dart b/lib/pages/personal/change_nick_name_page.dart new file mode 100644 index 00000000..eb88ae78 --- /dev/null +++ b/lib/pages/personal/change_nick_name_page.dart @@ -0,0 +1,84 @@ +import 'package:akuCommunity/provider/user_provider.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; +import 'package:random_character/random_character.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class ChangeNickName extends StatefulWidget { + ChangeNickName({Key key}) : super(key: key); + + @override + _ChangeNickNameState createState() => _ChangeNickNameState(); +} + +class _ChangeNickNameState extends State { + TextEditingController _textEditingController; + @override + void initState() { + final userProvider = Provider.of(context, listen: false); + super.initState(); + _textEditingController = + TextEditingController(text: userProvider.userInfoModel.nickName); + } + + @override + void dispose() { + _textEditingController?.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final userProvider = Provider.of(context); + return BeeScaffold( + title: '修改昵称', + body: Material( + color: Colors.white, + child: Padding( + padding: EdgeInsets.symmetric(horizontal: 32.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + 55.heightBox, + '昵称'.text.black.size(28.sp).make(), + TextFormField( + controller: _textEditingController, + decoration: InputDecoration( + contentPadding: EdgeInsets.zero, + hintText: '${userProvider.userInfoModel.nickName}', + border: UnderlineInputBorder( + borderSide: BorderSide( + color: Color(0xFFEEEEEE), + width: 1.w, + )), + ), + ), + 150.heightBox, + MaterialButton( + onPressed: () { + userProvider.setName(_textEditingController.text); + Get.back(); + }, + child: '保存'.text.black.size(32.sp).make(), + color: Color(0xFFFFC40C), + elevation: 0, + minWidth: 686.w, + height: 85.w, + ), + 24.heightBox, + '为保护个人隐私,在与邻里交往时显示昵称,默认为真实姓名,您可自行修改' + .text + .color(Color(0xFF999999)) + .size(24.sp) + .maxLines(2) + .make() + ], + ), + ), + ), + ); + } +} diff --git a/lib/pages/personal/user_profile_page.dart b/lib/pages/personal/user_profile_page.dart index 74b81b88..991fead2 100644 --- a/lib/pages/personal/user_profile_page.dart +++ b/lib/pages/personal/user_profile_page.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/pages/personal/change_nick_name_page.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/widget/bee_scaffold.dart'; import 'package:akuCommunity/utils/headers.dart'; @@ -70,7 +71,9 @@ class _UserProfilePageState extends State { _buildTile( '昵称', userProvider.userInfoModel.nickName.text.make(), - onPressed: () {}, + onPressed: () { + ChangeNickName().to(); + }, ), _buildTile( '手机号', diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 6daacb8e..0339a090 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -74,6 +74,14 @@ class UserProvider extends ChangeNotifier { //修改昵称 Future setName(String name) async { - //TODO set name + BaseModel baseModel = await NetUtil().post( + API.user.updateNickName, + params: {'nickName': name}, + showMessage: true, + ); + if (baseModel.status) { + _userInfoModel.nickName = name; + notifyListeners(); + } } } diff --git a/pubspec.lock b/pubspec.lock index b7f439f9..1ebc203a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -805,13 +805,6 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.2.0" - quiver: - dependency: transitive - description: - name: quiver - url: "https://pub.flutter-io.cn" - source: hosted - version: "2.1.3" random_character: dependency: "direct main" description: