From ee90fb6fc09f9c725ddea70ad1ce6902a5213dca Mon Sep 17 00:00:00 2001 From: Weller <1812208341@qq.com> Date: Thu, 17 Sep 2020 11:23:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=AA=E4=BA=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E6=94=B9=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dart_tool/package_config.json | 2 +- .../mine_detail_page/mine_detail_bloc.dart | 33 +++++++++++++++++-- .../models/mine_detail_model.dart | 8 +++++ .../models/mine_detail_model.g.dart | 4 +++ .../mine_header/mine_header_container.dart | 12 +++++-- 5 files changed, 52 insertions(+), 7 deletions(-) diff --git a/.dart_tool/package_config.json b/.dart_tool/package_config.json index 969db68..fbcec99 100644 --- a/.dart_tool/package_config.json +++ b/.dart_tool/package_config.json @@ -710,7 +710,7 @@ "languageVersion": "2.1" } ], - "generated": "2020-09-16T07:59:23.044545Z", + "generated": "2020-09-17T03:20:15.312540Z", "generator": "pub", "generatorVersion": "2.7.2" } diff --git a/lib/pages/mine_detail_page/mine_detail_bloc.dart b/lib/pages/mine_detail_page/mine_detail_bloc.dart index feb7750..a20d054 100644 --- a/lib/pages/mine_detail_page/mine_detail_bloc.dart +++ b/lib/pages/mine_detail_page/mine_detail_bloc.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert' as convert; import 'dart:io'; import 'package:fluttertoast/fluttertoast.dart'; @@ -37,12 +38,17 @@ class MineDetailBloc extends BlocBase { } /* 更新用户信息 + avatar 头像url nickname 昵称 gender 性别(1女2男3未知) birthday 生日(时间戳) * */ - void updateUser({String nickname, String gender, String birthday}) { + void updateUser( + {String avatar, String nickname, String gender, String birthday}) { Map params = Map(); + if (avatar != null && avatar != '') { + params['avatar'] = avatar; + } if (nickname != null && nickname != '') { params['nickname'] = nickname; } @@ -70,14 +76,35 @@ class MineDetailBloc extends BlocBase { params['dir'] = 'avatar'; params['file_size'] = originBytes.length; params['file_name'] = basename(file.path); - NetUtil.request('/api/v1/file/upload', + NetUtil.request('/api/v1/img/upload', method: NetMethod.PUT, params: params, - onCache: (data) {}, onSuccess: (data) { + onCache: (data) {}, onSuccess: (data) async { String method = data['method']; String host = data['host']; String key = data['key']; String token = data['token']; + + var result = await NetUtil.uploadFile(host, file, + params: { + 'key': key, + 'token': token, + }, + method: method); + print(result.toString()); + Map json = convert.jsonDecode(result.toString()); + + String filename = json['fname'] ?? ''; + print(filename); + String imageUrl = + '${_user.fileBucketUrl.toString()}${filename.toString()}'; + if (_user.format != null && _user.format != '') { + imageUrl += _user.format; + imageUrl += '/${DateTime.now().millisecondsSinceEpoch.toString()}'; + } else { + imageUrl += '?${DateTime.now().millisecondsSinceEpoch.toString()}'; + } + updateUser(avatar: imageUrl); }); } } diff --git a/lib/pages/mine_detail_page/models/mine_detail_model.dart b/lib/pages/mine_detail_page/models/mine_detail_model.dart index 63386f8..df982ac 100644 --- a/lib/pages/mine_detail_page/models/mine_detail_model.dart +++ b/lib/pages/mine_detail_page/models/mine_detail_model.dart @@ -19,12 +19,20 @@ class MineDetailModel extends Object { @JsonKey(name: 'register_time') String registerTime; + @JsonKey(name: 'file_bucket_url') + String fileBucketUrl; + + @JsonKey(name: 'file_format') + String format; + MineDetailModel( this.avatar, this.nickname, this.gender, this.birthday, this.registerTime, + this.fileBucketUrl, + this.format, ); factory MineDetailModel.fromJson(Map srcJson) => diff --git a/lib/pages/mine_detail_page/models/mine_detail_model.g.dart b/lib/pages/mine_detail_page/models/mine_detail_model.g.dart index 6caa278..0bd1061 100644 --- a/lib/pages/mine_detail_page/models/mine_detail_model.g.dart +++ b/lib/pages/mine_detail_page/models/mine_detail_model.g.dart @@ -13,6 +13,8 @@ MineDetailModel _$MineDetailModelFromJson(Map json) { json['gender'] as String, json['birthday'] as String, json['register_time'] as String, + json['file_bucket_url'] as String, + json['file_format'] as String, ); } @@ -23,4 +25,6 @@ Map _$MineDetailModelToJson(MineDetailModel instance) => 'gender': instance.gender, 'birthday': instance.birthday, 'register_time': instance.registerTime, + 'file_bucket_url': instance.fileBucketUrl, + 'file_format': instance.format, }; diff --git a/lib/widgets/mine/mine_header/mine_header_container.dart b/lib/widgets/mine/mine_header/mine_header_container.dart index fb2f104..e742c4c 100644 --- a/lib/widgets/mine/mine_header/mine_header_container.dart +++ b/lib/widgets/mine/mine_header/mine_header_container.dart @@ -52,9 +52,15 @@ class _MineHeaderContainerState extends State { left: 20, top: 20, bottom: 20, right: 12), width: 56, height: 56, - child: CachedNetworkImage( - imageUrl: profile.avatar, - fit: BoxFit.cover, + decoration: BoxDecoration( + color: Color(0xfff3f3f3), + borderRadius: BorderRadius.circular(28)), + child: ClipRRect( + borderRadius: BorderRadius.circular(28), + child: CachedNetworkImage( + imageUrl: profile.avatar, + fit: BoxFit.cover, + ), ), ), onTap: () {