From 80e1b404180b5d31d4254b9afcf344f7523c9d97 Mon Sep 17 00:00:00 2001 From: laiiihz Date: Wed, 24 Feb 2021 10:03:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E4=BF=AE=E6=94=B9=E5=A4=B4?= =?UTF-8?q?=E5=83=8F=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/const/api.dart | 8 ++++++++ lib/provider/user_provider.dart | 28 ++++++++++++++++++++++------ lib/ui/settings/user_info_page.dart | 15 +++++++-------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/lib/const/api.dart b/lib/const/api.dart index 069bace..bdb33c0 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -14,6 +14,7 @@ class API { static _Auth auth = _Auth(); static _User user = _User(); static _Manage manage = _Manage(); + static _Upload upload = _Upload(); } class _Auth { @@ -42,6 +43,8 @@ class _User { ///个人资料:根据新手机号发送修改验证码 String get updateTel => '/user/personalData/updateTel'; + ///个人资料:修改管家用户头像 + String get updateAvatar => '/user/personalData/updateHeadPortrait'; } class _Manage { @@ -93,3 +96,8 @@ class _Manage { ///物品出户:不放行 String get goodsOutNotRelease => '/user/articleOut/noRelease'; } + +class _Upload { + ///上传个人资料头像照片 + String get avatar => '/user/upload/butlerAppHeadSculpture'; +} diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 4c5261c..2a74e73 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -2,6 +2,8 @@ import 'dart:io'; // Flutter imports: +import 'package:aku_community_manager/utils/network/base_file_model.dart'; +import 'package:bot_toast/bot_toast.dart'; import 'package:flutter/material.dart'; // Project imports: @@ -87,20 +89,34 @@ class UserProvider extends ChangeNotifier { _isSigned = true; notifyListeners(); } -///修改昵称 + + ///修改昵称 setNickName(String name) { _infoModel.nickName = name; notifyListeners(); } - setAvatar(File file) { - _userInfoModel.avatar = file; - notifyListeners(); + ///修改头像 + setAvatar(File file) async { + Function cancel = BotToast.showLoading(); + BaseFileModel fileModel = await NetUtil().upload(API.upload.avatar, file); + if (fileModel.status == true) { + await NetUtil().post( + API.user.updateAvatar, + params: { + 'fileUrls': [fileModel.url], + }, + showMessage: true, + ); + await updateProfile(); + cancel(); + notifyListeners(); + } } ///修改手机 - setTel(String tel){ - _profileModel.tel=tel; + setTel(String tel) { + _profileModel.tel = tel; notifyListeners(); } } diff --git a/lib/ui/settings/user_info_page.dart b/lib/ui/settings/user_info_page.dart index 948baee..f821789 100644 --- a/lib/ui/settings/user_info_page.dart +++ b/lib/ui/settings/user_info_page.dart @@ -1,4 +1,6 @@ // Flutter imports: +import 'dart:io'; + import 'package:aku_community_manager/tools/aku_divider.dart'; import 'package:aku_community_manager/ui/settings/nick_name_change_page.dart'; import 'package:aku_community_manager/ui/settings/tel_change_page.dart'; @@ -35,10 +37,9 @@ class _UserInfoPageState extends State { padding: EdgeInsets.symmetric(vertical: 24.w), children: [ AkuTile( - onTap: () { - akuPickImage().then((file) { - if (file != null) userProvider.setAvatar(file); - }); + onTap: () async { + File file = await akuPickImage(); + if (file != null) await userProvider.setAvatar(file); }, title: Text('头像'), height: 168.w, @@ -53,11 +54,9 @@ class _UserInfoPageState extends State { suffix: Text(userProvider.infoModel.nickName), ), AkuTile( - onTap: () async{ + onTap: () async { await TelChangePage().to(); - setState(() { - - }); + setState(() {}); }, title: Text('手机'), suffix: Text(TextUtil.hideNumber(userProvider.profileModel.tel)),