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