|
|
@ -1,17 +1,11 @@
|
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:music_player_miao/widget/text_field.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
import '../../api/api_client.dart';
|
|
|
|
import '../../api/api_client.dart';
|
|
|
|
import '../../api/api_client_info.dart';
|
|
|
|
import '../../api/api_client_info.dart';
|
|
|
|
import '../../common_widget/app_data.dart';
|
|
|
|
import '../../common_widget/app_data.dart';
|
|
|
|
import '../../models/getInfo_bean.dart';
|
|
|
|
|
|
|
|
import '../../models/universal_bean.dart';
|
|
|
|
|
|
|
|
import '../../view_model/home_view_model.dart';
|
|
|
|
import '../../view_model/home_view_model.dart';
|
|
|
|
import 'package:image_picker/image_picker.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UserInfo extends StatefulWidget {
|
|
|
|
class UserInfo extends StatefulWidget {
|
|
|
|
const UserInfo({super.key});
|
|
|
|
const UserInfo({super.key});
|
|
|
@ -23,7 +17,7 @@ class UserInfo extends StatefulWidget {
|
|
|
|
class _UserInfoState extends State<UserInfo> {
|
|
|
|
class _UserInfoState extends State<UserInfo> {
|
|
|
|
final listVM = Get.put(HomeViewModel());
|
|
|
|
final listVM = Get.put(HomeViewModel());
|
|
|
|
final TextEditingController _controller = TextEditingController();
|
|
|
|
final TextEditingController _controller = TextEditingController();
|
|
|
|
late File _selectedImage;
|
|
|
|
File? _selectedImage;
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
@ -42,7 +36,7 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
elevation: 0,
|
|
|
|
elevation: 0,
|
|
|
|
leading: IconButton(
|
|
|
|
leading: IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
onPressed: () {
|
|
|
|
Get.back();
|
|
|
|
Get.back(result: true);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
icon: Image.asset(
|
|
|
|
icon: Image.asset(
|
|
|
|
"assets/img/back.png",
|
|
|
|
"assets/img/back.png",
|
|
|
@ -60,7 +54,18 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
body: SingleChildScrollView(
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
_buildAvatarRow(),
|
|
|
|
|
|
|
|
_buildNicknameRow(),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建头像行
|
|
|
|
|
|
|
|
Widget _buildAvatarRow() {
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
height: 80,
|
|
|
|
height: 80,
|
|
|
|
color: Colors.white.withOpacity(0.6),
|
|
|
|
color: Colors.white.withOpacity(0.6),
|
|
|
|
padding: const EdgeInsets.only(left: 48, right: 25),
|
|
|
|
padding: const EdgeInsets.only(left: 48, right: 25),
|
|
|
@ -77,26 +82,24 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
children: [
|
|
|
|
Image.network(
|
|
|
|
_buildAvatarImage(),
|
|
|
|
AppData().currentAvatar,
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
width: 64,
|
|
|
|
|
|
|
|
height: 64,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
const SizedBox(
|
|
|
|
|
|
|
|
width: 20,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
Image.asset(
|
|
|
|
Image.asset(
|
|
|
|
"assets/img/user_next.png",
|
|
|
|
"assets/img/user_next.png",
|
|
|
|
width: 25,
|
|
|
|
width: 25,
|
|
|
|
height: 25,
|
|
|
|
height: 25,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构建昵称行
|
|
|
|
|
|
|
|
Widget _buildNicknameRow() {
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
height: 80,
|
|
|
|
height: 80,
|
|
|
|
color: Colors.white.withOpacity(0.6),
|
|
|
|
color: Colors.white.withOpacity(0.6),
|
|
|
|
padding: const EdgeInsets.only(left: 48, right: 25),
|
|
|
|
padding: const EdgeInsets.only(left: 48, right: 25),
|
|
|
@ -117,27 +120,38 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
AppData().currentUsername,
|
|
|
|
AppData().currentUsername,
|
|
|
|
style: const TextStyle(fontSize: 20),
|
|
|
|
style: const TextStyle(fontSize: 20),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
const SizedBox(width: 15),
|
|
|
|
width: 15,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
Image.asset(
|
|
|
|
Image.asset(
|
|
|
|
"assets/img/user_next.png",
|
|
|
|
"assets/img/user_next.png",
|
|
|
|
width: 25,
|
|
|
|
width: 25,
|
|
|
|
height: 25,
|
|
|
|
height: 25,
|
|
|
|
)
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 显示头像的 Widget,根据是否是网络 URL 或本地路径来动态加载
|
|
|
|
|
|
|
|
Widget _buildAvatarImage() {
|
|
|
|
|
|
|
|
final avatarPath = AppData().currentAvatar;
|
|
|
|
|
|
|
|
if (avatarPath.startsWith('http')) {
|
|
|
|
|
|
|
|
return Image.network(
|
|
|
|
|
|
|
|
avatarPath,
|
|
|
|
|
|
|
|
width: 64,
|
|
|
|
|
|
|
|
height: 64,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return Image.file(
|
|
|
|
|
|
|
|
File(avatarPath),
|
|
|
|
|
|
|
|
width: 64,
|
|
|
|
|
|
|
|
height: 64,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Future _bottomSheet(BuildContext context) async {
|
|
|
|
Future _bottomSheet(BuildContext context) async {
|
|
|
|
final picker = ImagePicker();
|
|
|
|
final picker = ImagePicker();
|
|
|
|
await showModalBottomSheet(
|
|
|
|
await showModalBottomSheet(
|
|
|
@ -146,7 +160,7 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(30))),
|
|
|
|
borderRadius: BorderRadius.vertical(top: Radius.circular(30))),
|
|
|
|
builder: (context) => Container(
|
|
|
|
builder: (context) => Container(
|
|
|
|
height: 132,
|
|
|
|
height: 80,
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
padding: const EdgeInsets.only(top: 20),
|
|
|
|
child: Column(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
@ -157,18 +171,19 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
final pickedFile =
|
|
|
|
final pickedFile =
|
|
|
|
await picker.pickImage(source: ImageSource.gallery);
|
|
|
|
await picker.pickImage(source: ImageSource.gallery);
|
|
|
|
if (pickedFile != null) {
|
|
|
|
if (pickedFile != null) {
|
|
|
|
_selectedImage=File('assets/images/bg.png');
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
_selectedImage = File(pickedFile.path);
|
|
|
|
_selectedImage = File(pickedFile.path);
|
|
|
|
print(_selectedImage);
|
|
|
|
setState(() {}); // 更新 UI
|
|
|
|
});
|
|
|
|
|
|
|
|
UniversalBean bean = await ChangeApiClient().changeHeader(
|
|
|
|
// 上传头像
|
|
|
|
|
|
|
|
await ChangeApiClient().changeHeader(
|
|
|
|
Authorization: AppData().currentToken,
|
|
|
|
Authorization: AppData().currentToken,
|
|
|
|
avatar: _selectedImage);
|
|
|
|
avatar: _selectedImage!);
|
|
|
|
GetInfoBean bean1 = await GetInfoApiClient().getInfo(
|
|
|
|
|
|
|
|
|
|
|
|
// 更新本地存储
|
|
|
|
|
|
|
|
_updatetouxiang(_selectedImage!.path);
|
|
|
|
|
|
|
|
// 拉取更新后的用户信息
|
|
|
|
|
|
|
|
await GetInfoApiClient().getInfo(
|
|
|
|
Authorization: AppData().currentToken);
|
|
|
|
Authorization: AppData().currentToken);
|
|
|
|
AppData appData = AppData();
|
|
|
|
|
|
|
|
appData.box.write('currentAvatar', AppData().currentAvatar);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
@ -182,24 +197,10 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 18),
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 18),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
ElevatedButton(
|
|
|
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
|
|
|
backgroundColor: const Color(0xff429482),
|
|
|
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 18),
|
|
|
|
|
|
|
|
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
|
|
|
|
|
|
shape: const RoundedRectangleBorder(
|
|
|
|
|
|
|
|
borderRadius: BorderRadius.zero,
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
child: const Text(
|
|
|
|
|
|
|
|
"取消",
|
|
|
|
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 18),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void _showNicknameDialog() {
|
|
|
|
void _showNicknameDialog() {
|
|
|
@ -212,46 +213,44 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
"修改昵称",
|
|
|
|
"修改昵称",
|
|
|
|
style: TextStyle(fontSize: 20),
|
|
|
|
style: TextStyle(fontSize: 20),
|
|
|
|
)),
|
|
|
|
)),
|
|
|
|
content: TextFieldColor(
|
|
|
|
content: TextField(
|
|
|
|
controller: _controller,
|
|
|
|
controller: _controller,
|
|
|
|
hintText: '请输入新昵称',
|
|
|
|
decoration: const InputDecoration(hintText: '请输入新昵称'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
actions: <Widget>[
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
onPressed: () async {
|
|
|
|
|
|
|
|
_updateNickname();
|
|
|
|
|
|
|
|
await ChangeApiClient().changeName(
|
|
|
|
|
|
|
|
Authorization: AppData().currentToken,
|
|
|
|
|
|
|
|
userName: AppData().currentUsername);
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
backgroundColor: const Color(0xff429482),
|
|
|
|
backgroundColor: const Color(0xff429482),
|
|
|
|
minimumSize: const Size(130, 50),
|
|
|
|
minimumSize: const Size(130, 50),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
BorderRadius.circular(5.0), // Adjust the radius as needed
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: const Text(
|
|
|
|
child: const Text(
|
|
|
|
"取消",
|
|
|
|
"保存",
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
TextButton(
|
|
|
|
onPressed: () async {
|
|
|
|
onPressed: () {
|
|
|
|
_updateNickname();
|
|
|
|
|
|
|
|
UniversalBean bean = await ChangeApiClient().changeName(
|
|
|
|
|
|
|
|
Authorization: AppData().currentToken,
|
|
|
|
|
|
|
|
userName: AppData().currentUsername);
|
|
|
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
style: TextButton.styleFrom(
|
|
|
|
backgroundColor: const Color(0xff429482),
|
|
|
|
backgroundColor: const Color(0xff429482),
|
|
|
|
minimumSize: const Size(130, 50),
|
|
|
|
minimumSize: const Size(130, 50),
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
borderRadius:
|
|
|
|
borderRadius: BorderRadius.circular(5.0),
|
|
|
|
BorderRadius.circular(5.0), // Adjust the radius as needed
|
|
|
|
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: const Text(
|
|
|
|
child: const Text(
|
|
|
|
"保存",
|
|
|
|
"取消",
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
style: TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
@ -267,4 +266,14 @@ class _UserInfoState extends State<UserInfo> {
|
|
|
|
appData.box.write('currentUsername', _controller.text);
|
|
|
|
appData.box.write('currentUsername', _controller.text);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _updatetouxiang(String path) {
|
|
|
|
|
|
|
|
setState(() {
|
|
|
|
|
|
|
|
AppData appData = AppData();
|
|
|
|
|
|
|
|
appData.box.write('currentAvatar', path); // 更新头像路径到本地存储
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|