diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 7f583772..6a34c578 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -1,6 +1,15 @@ class API { - static const String host = 'http://192.168.2.201:8804/IntelligentCommunity'; + ///HOST + static const String host = 'http://192.168.2.201:8804'; + + ///接口基础地址 + static const String baseURL = '$host/IntelligentCommunity/app'; + + ///静态资源路径 static String get resource => '$host/static'; + + static String image(String path) => '$resource$path'; + static const int networkTimeOut = 10000; static _Login login = _Login(); static _User user = _User(); diff --git a/lib/model/user/user_info_model.dart b/lib/model/user/user_info_model.dart index 58c0131a..869a9a5e 100644 --- a/lib/model/user/user_info_model.dart +++ b/lib/model/user/user_info_model.dart @@ -2,7 +2,7 @@ import 'package:common_utils/common_utils.dart'; class UserInfoModel { int id; - List imgUrls; + String imgUrl; String name; String nickName; String tel; @@ -28,7 +28,7 @@ class UserInfoModel { UserInfoModel( {this.id, - this.imgUrls, + this.imgUrl, this.name, this.nickName, this.tel, @@ -37,23 +37,12 @@ class UserInfoModel { UserInfoModel.fromJson(Map json) { id = json['id']; - imgUrls = json['imgUrls'].cast(); + if (json['imgUrls'] != null) + imgUrl = (json['imgUrls'] as List).first['url']; name = json['name']; nickName = json['nickName']; tel = json['tel']; sex = json['sex']; birthday = json['birthday']; } - - Map toJson() { - final Map data = new Map(); - data['id'] = this.id; - data['imgUrls'] = this.imgUrls; - data['name'] = this.name; - data['nickName'] = this.nickName; - data['tel'] = this.tel; - data['sex'] = this.sex; - data['birthday'] = this.birthday; - return data; - } } diff --git a/lib/pages/personal/personal_page.dart b/lib/pages/personal/personal_page.dart index 2974b991..064bdc9b 100644 --- a/lib/pages/personal/personal_page.dart +++ b/lib/pages/personal/personal_page.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/const/resource.dart'; +import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/pages/activities_page/activities_page.dart'; import 'package:akuCommunity/pages/address_page/address_page.dart'; import 'package:akuCommunity/pages/life_pay/life_pay_page.dart'; @@ -118,14 +119,16 @@ class _PersonalIndexState extends State margin: EdgeInsets.only(left: 32.w), child: Row( children: [ - Container( + Hero( + tag: 'AVATAR', child: ClipOval( - child: CachedImageWrapper( - url: - 'https://dss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1851283359,3457678391&fm=26&gp=0.jpg', - width: 106.w, + child: FadeInImage.assetNetwork( + //TODO PLACEHOLDER + placeholder: R.ASSETS_ICONS_PROPOSAL_PNG, + image: API + .image(userProvider.userInfoModel.imgUrl), height: 106.w, - isSigned: userProvider.isSigned, + width: 106.w, ), ), ), diff --git a/lib/pages/personal/user_profile_page.dart b/lib/pages/personal/user_profile_page.dart index c2c26432..1e2d79fa 100644 --- a/lib/pages/personal/user_profile_page.dart +++ b/lib/pages/personal/user_profile_page.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/const/resource.dart'; import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/pages/personal/change_nick_name_page.dart'; import 'package:akuCommunity/pages/personal/update_tel_page.dart'; @@ -105,7 +106,21 @@ class _UserProfilePageState extends State { title: '个人资料', body: ListView( children: [ - _buildTile('头像', CircleAvatar(), onPressed: _pickAvatar), + _buildTile( + '头像', + Hero( + tag: 'AVATAR', + child: ClipOval( + child: FadeInImage.assetNetwork( + placeholder: R.ASSETS_ICONS_PROPOSAL_PNG, + image: API.image(userProvider.userInfoModel.imgUrl), + height: 56.w, + width: 56.w, + ), + ), + ), + onPressed: _pickAvatar, + ), _buildTile( '姓名', userProvider.userInfoModel.name.text.make(), diff --git a/lib/pages/sign/sign_func.dart b/lib/pages/sign/sign_func.dart index 5f246ecc..147daef9 100644 --- a/lib/pages/sign/sign_func.dart +++ b/lib/pages/sign/sign_func.dart @@ -82,6 +82,7 @@ class SignFunc { BaseModel baseModel = await NetUtil().get( API.user.userDetail, ); + if (baseModel.data == null) return null; return UserDetailModel.fromJson(baseModel.data); } } diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index b832b54b..60e6eec5 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -125,8 +125,7 @@ class UserProvider extends ChangeNotifier { showMessage: true, ); if (model.status) { - _userInfoModel.imgUrls = [path]; - notifyListeners(); + await updateProfile(); } } } diff --git a/lib/utils/network/net_util.dart b/lib/utils/network/net_util.dart index 38fe3922..d7e95334 100644 --- a/lib/utils/network/net_util.dart +++ b/lib/utils/network/net_util.dart @@ -30,7 +30,7 @@ class NetUtil { errorMethodCount: 4, )); BaseOptions options = BaseOptions( - baseUrl: '${API.host}/app', + baseUrl: API.baseURL, connectTimeout: API.networkTimeOut, receiveTimeout: API.networkTimeOut, sendTimeout: API.networkTimeOut, @@ -172,8 +172,8 @@ class NetUtil { _parseRequestError(BaseModel model, {bool showMessage = false}) { final userProvider = Provider.of(Get.context, listen: false); if (!model.status && model.message == '登录失效,请登录') { - Get.offAll(SignInPage()); userProvider.logout(); + Get.offAll(SignInPage()); } if (!model.status || showMessage) { BotToast.showText(text: model.message);