Ver código fonte

添加个人信息修改头像

tags/0.0.1
Weller 4 anos atrás
pai
commit
ee90fb6fc0
5 arquivos alterados com 52 adições e 7 exclusões
  1. +1
    -1
      .dart_tool/package_config.json
  2. +30
    -3
      lib/pages/mine_detail_page/mine_detail_bloc.dart
  3. +8
    -0
      lib/pages/mine_detail_page/models/mine_detail_model.dart
  4. +4
    -0
      lib/pages/mine_detail_page/models/mine_detail_model.g.dart
  5. +9
    -3
      lib/widgets/mine/mine_header/mine_header_container.dart

+ 1
- 1
.dart_tool/package_config.json Ver arquivo

@@ -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"
}

+ 30
- 3
lib/pages/mine_detail_page/mine_detail_bloc.dart Ver arquivo

@@ -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<String, dynamic> 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<String, dynamic> 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);
});
}
}

+ 8
- 0
lib/pages/mine_detail_page/models/mine_detail_model.dart Ver arquivo

@@ -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<String, dynamic> srcJson) =>


+ 4
- 0
lib/pages/mine_detail_page/models/mine_detail_model.g.dart Ver arquivo

@@ -13,6 +13,8 @@ MineDetailModel _$MineDetailModelFromJson(Map<String, dynamic> 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<String, dynamic> _$MineDetailModelToJson(MineDetailModel instance) =>
'gender': instance.gender,
'birthday': instance.birthday,
'register_time': instance.registerTime,
'file_bucket_url': instance.fileBucketUrl,
'file_format': instance.format,
};

+ 9
- 3
lib/widgets/mine/mine_header/mine_header_container.dart Ver arquivo

@@ -52,9 +52,15 @@ class _MineHeaderContainerState extends State<MineHeaderContainer> {
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: () {


Carregando…
Cancelar
Salvar