You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
MTMusic/lib/api/api_client_info.dart

61 lines
1.6 KiB

11 months ago
import 'dart:io';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
11 months ago
import '../models/universal_bean.dart';
const String _changeNameURL = 'http://flyingpig.fun:10010/users/username';
const String _changeHeaderURL = 'http://flyingpig.fun:10010/users/avatar';
class ChangeApiClient {
final Dio dio = Dio();
final ValueNotifier<String> avatarUrlNotifier = ValueNotifier<String>("");
11 months ago
///修改昵称
Future<UniversalBean> changeName({
required String Authorization,
required String userName
}) async {
Response response = await dio.put(
_changeNameURL,
// data: {
// 'Authorization': Authorization,
// },
11 months ago
queryParameters: {'userName':userName},
options: Options(
headers:{
'Authorization':Authorization,
'Content-Type':'application/json;charset=UTF-8'
}
)
11 months ago
);
print(response.data);
11 months ago
return UniversalBean.formMap(response.data);
}
///修改头像
Future<UniversalBean> changeHeader({
required String Authorization,
required File avatar,
}) async {
FormData formData = FormData.fromMap({
// 'Authorization': Authorization,
11 months ago
'avatar': await MultipartFile.fromFile(avatar.path, filename: 'avatar.jpg'),
});
Response response = await dio.put(
_changeHeaderURL,
data: formData,
options: Options(
headers: {
'Authorization': Authorization,
'Content-Type': 'multipart/form-data',
},
),
);
print(response.data);
avatarUrlNotifier.value = avatar.path;
11 months ago
return UniversalBean.formMap(response.data);
}
}