520 lines
28 KiB
Dart
520 lines
28 KiB
Dart
import 'package:EasyDartModule/EasyDartModule.dart' as edm;
|
||
import 'package:ef/ef.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||
import 'package:vbvs_app/common/color/appConstants.dart';
|
||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||
import 'package:vbvs_app/component/tool/ClickableContainer.dart';
|
||
import 'package:vbvs_app/component/tool/CustomCard.dart';
|
||
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
|
||
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
|
||
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
|
||
import 'package:vbvs_app/controller/person/person_controller.dart';
|
||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||
import 'package:vbvs_app/model/api_response.dart';
|
||
import 'package:flutter/services.dart';
|
||
|
||
class EditUserPage extends StatefulWidget {
|
||
EditUserPage({super.key});
|
||
|
||
@override
|
||
State<EditUserPage> createState() => _UpdateUserPageState();
|
||
}
|
||
|
||
class _UpdateUserPageState extends State<EditUserPage> {
|
||
GlobalController globalController = Get.find();
|
||
UserInfoController userInfoController = Get.find();
|
||
BlueteethBindController blueteethBindController = Get.find();
|
||
PersonController personController = Get.find();
|
||
ThemeController themeController = Get.find();
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
userInfoController.model.user!.tmpHead = null;
|
||
userInfoController.model.user!.tmpNickName = null;
|
||
userInfoController.model.user!.tmpHead =
|
||
userInfoController.model.user!.avatar;
|
||
userInfoController.model.user!.tmpNickName =
|
||
userInfoController.model.user!.nick_name;
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
int login = userInfoController.model.login!;
|
||
return LayoutBuilder(
|
||
builder: (context, bodySize) => GestureDetector(
|
||
// onTap: () => FocusScope.of(context).unfocus(),,
|
||
child: Container(
|
||
decoration: BoxDecoration(
|
||
image: DecorationImage(
|
||
image: AssetImage('assets/images/new_background.png'),
|
||
fit: BoxFit.fill,
|
||
),
|
||
),
|
||
child: Scaffold(
|
||
backgroundColor: Colors.transparent,
|
||
appBar: AppBar(
|
||
systemOverlayStyle: SystemUiOverlayStyle(
|
||
statusBarColor: Colors.transparent, // 状态栏背景色
|
||
statusBarIconBrightness: Brightness.light, // 图标颜色(Android)
|
||
statusBarBrightness: Brightness.light, // 图标颜色(iOS)
|
||
),
|
||
backgroundColor: Colors.transparent,
|
||
automaticallyImplyLeading: false,
|
||
iconTheme: IconThemeData(
|
||
color: themeController.currentColor.sc3,
|
||
),
|
||
titleSpacing: 0,
|
||
title: Container(
|
||
width: double.infinity,
|
||
height: 180.rpx,
|
||
child: Stack(
|
||
alignment: Alignment.center,
|
||
children: [
|
||
Text(
|
||
'编辑资料'.tr,
|
||
style: TextStyle(
|
||
fontFamily: 'Readex Pro',
|
||
color: themeController.currentColor.sc3,
|
||
letterSpacing: 0,
|
||
fontSize: 30.rpx,
|
||
),
|
||
),
|
||
Positioned(
|
||
left: 0.rpx,
|
||
child: returnIconButtomNew(),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
actions: [],
|
||
centerTitle: false,
|
||
),
|
||
body: SafeArea(
|
||
top: true,
|
||
child: Container(
|
||
width: double.infinity,
|
||
height: double.infinity,
|
||
decoration: BoxDecoration(),
|
||
child: Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx, 0.rpx, 30.rpx, 0.rpx),
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Container(
|
||
child: Column(
|
||
children: [
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
0.rpx, 76.rpx, 0.rpx, 0.rpx),
|
||
child: Container(
|
||
width:
|
||
MediaQuery.sizeOf(context).width * 0.213,
|
||
height:
|
||
MediaQuery.sizeOf(context).height * 0.098,
|
||
constraints: BoxConstraints(
|
||
minWidth: 160.rpx,
|
||
minHeight: 160.rpx,
|
||
),
|
||
decoration: BoxDecoration(),
|
||
child: Obx(() {
|
||
return getImageWidget(context);
|
||
})),
|
||
),
|
||
Padding(
|
||
padding: EdgeInsets.symmetric(
|
||
vertical: 38.rpx), // 保持上下间距
|
||
child: Center(
|
||
child: ClickableContainer(
|
||
backgroundColor: Colors.transparent,
|
||
highlightColor:
|
||
themeController.currentColor.sc2,
|
||
borderRadius: 8.rpx, // 可选,点击反馈更明显
|
||
padding: EdgeInsets.symmetric(
|
||
horizontal: 12.rpx,
|
||
vertical: 12.rpx), // 控制点击热区大小
|
||
onTap: () async {
|
||
edm.EasyDartModule.logger.info(
|
||
"${userInfoController.model.user!}点击上传头像");
|
||
DailyLogUtils.writeLog(
|
||
"${userInfoController.model.user!}点击上传头像");
|
||
ApiResponse apiResponse =
|
||
await userInfoController.uploadImg();
|
||
TopSlideNotification.show(
|
||
context,
|
||
text: apiResponse.msg!,
|
||
textColor: apiResponse.code ==
|
||
HttpStatusCodes.ok
|
||
? themeController.currentColor.sc2
|
||
: themeController.currentColor.sc9,
|
||
);
|
||
},
|
||
child: Text(
|
||
'点击更换头像'.tr,
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
fontSize: 26.rpx,
|
||
letterSpacing: 0.0,
|
||
color: stringToColor("#85F5FF"),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
// Padding(
|
||
// padding: EdgeInsetsDirectional.fromSTEB(
|
||
// 30.rpx, 79.rpx, 30.rpx, 0.rpx),
|
||
// child: Container(
|
||
// width: double.infinity,
|
||
// decoration: BoxDecoration(
|
||
// border: Border(
|
||
// top: BorderSide(
|
||
// color: themeController.currentColor.sc4
|
||
// .withOpacity(0.5),
|
||
// width: AppConstants().border_width,
|
||
// ),
|
||
// bottom: BorderSide(
|
||
// color: themeController.currentColor.sc4
|
||
// .withOpacity(0.5),
|
||
// width: AppConstants().border_width,
|
||
// ),
|
||
// ),
|
||
// ),
|
||
// child: Row(
|
||
// mainAxisSize: MainAxisSize.max,
|
||
// mainAxisAlignment:
|
||
// MainAxisAlignment.spaceBetween,
|
||
// children: [
|
||
// Expanded(
|
||
// child: Row(
|
||
// mainAxisSize: MainAxisSize.max,
|
||
// children: [
|
||
// Expanded(
|
||
// child: Stack(
|
||
// children: [
|
||
// TextFormField(
|
||
// initialValue: userInfoController
|
||
// .model.user!.nick_name,
|
||
// onChanged: (value) {
|
||
// userInfoController.model.user!
|
||
// .tmpNickName = value;
|
||
// },
|
||
// maxLength:
|
||
// AppConstants().text_length,
|
||
// maxLines: 1,
|
||
// textAlign: TextAlign.center,
|
||
// textAlignVertical:
|
||
// TextAlignVertical.center,
|
||
// buildCounter: (_,
|
||
// {int? currentLength,
|
||
// bool? isFocused,
|
||
// int? maxLength}) =>
|
||
// null, // 禁用默认计数器
|
||
// decoration: InputDecoration(
|
||
// contentPadding:
|
||
// EdgeInsets.symmetric(
|
||
// vertical: 30.rpx),
|
||
// isDense: true,
|
||
// hintText: '未命名'.tr,
|
||
// hintStyle: TextStyle(
|
||
// fontFamily: 'Inter',
|
||
// fontSize: 26.rpx,
|
||
// color: themeController
|
||
// .currentColor.sc4,
|
||
// ),
|
||
// enabledBorder:
|
||
// OutlineInputBorder(
|
||
// borderSide: BorderSide(
|
||
// color:
|
||
// Colors.transparent,
|
||
// width: 1.rpx),
|
||
// borderRadius:
|
||
// BorderRadius.circular(
|
||
// 8.rpx),
|
||
// ),
|
||
// focusedBorder:
|
||
// OutlineInputBorder(
|
||
// borderSide: BorderSide(
|
||
// color:
|
||
// Colors.transparent,
|
||
// width: 1.rpx),
|
||
// borderRadius:
|
||
// BorderRadius.circular(
|
||
// 8.rpx),
|
||
// ),
|
||
// errorBorder:
|
||
// OutlineInputBorder(
|
||
// borderSide: BorderSide(
|
||
// width: 1.rpx),
|
||
// borderRadius:
|
||
// BorderRadius.circular(
|
||
// 8.rpx),
|
||
// ),
|
||
// focusedErrorBorder:
|
||
// OutlineInputBorder(
|
||
// borderSide: BorderSide(
|
||
// width: 1.rpx),
|
||
// borderRadius:
|
||
// BorderRadius.circular(
|
||
// 8.rpx),
|
||
// ),
|
||
// filled: false,
|
||
// ),
|
||
// style: TextStyle(
|
||
// fontFamily: 'Inter',
|
||
// fontSize: 26.rpx,
|
||
// color: themeController
|
||
// .currentColor.sc3,
|
||
// ),
|
||
// cursorColor: themeController
|
||
// .currentColor.sc3,
|
||
// ),
|
||
|
||
// // 自定义右下角计数器
|
||
// Positioned(
|
||
// bottom: 4.rpx,
|
||
// right: 8.rpx,
|
||
// child: Obx(() {
|
||
// final text =
|
||
// userInfoController
|
||
// .model
|
||
// .user!
|
||
// .tmpNickName ??
|
||
// '';
|
||
// return Text(
|
||
// '${text.length} / ${AppConstants().text_length}',
|
||
// style: TextStyle(
|
||
// fontSize: 20.rpx,
|
||
// color: Colors.grey,
|
||
// ),
|
||
// );
|
||
// }),
|
||
// ),
|
||
// ],
|
||
// )),
|
||
// ].divide(SizedBox(width: 27.rpx)),
|
||
// ),
|
||
// ),
|
||
// ],
|
||
// ),
|
||
// ),
|
||
// ),
|
||
Padding(
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
30.rpx, 79.rpx, 30.rpx, 0.rpx),
|
||
child: Container(
|
||
width: double.infinity,
|
||
decoration: BoxDecoration(
|
||
border: Border(
|
||
top: BorderSide(
|
||
color: themeController.currentColor.sc4
|
||
.withOpacity(0.5),
|
||
width: AppConstants().border_width,
|
||
),
|
||
bottom: BorderSide(
|
||
color: themeController.currentColor.sc4
|
||
.withOpacity(0.5),
|
||
width: AppConstants().border_width,
|
||
),
|
||
),
|
||
),
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
mainAxisAlignment:
|
||
MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Expanded(
|
||
child: Row(
|
||
mainAxisSize: MainAxisSize.max,
|
||
children: [
|
||
Expanded(
|
||
child: Center(
|
||
// 让输入框垂直居中对齐
|
||
child: TextFormField(
|
||
initialValue: userInfoController
|
||
.model.user!.nick_name,
|
||
onChanged: (value) {
|
||
userInfoController.model.user!
|
||
.tmpNickName = value;
|
||
},
|
||
maxLength: null, // 不限制字数
|
||
maxLines: 1,
|
||
textAlign: TextAlign.center,
|
||
textAlignVertical:
|
||
TextAlignVertical.center,
|
||
buildCounter: (_,
|
||
{int? currentLength,
|
||
bool? isFocused,
|
||
int? maxLength}) =>
|
||
null,
|
||
decoration: InputDecoration(
|
||
contentPadding:
|
||
EdgeInsets.symmetric(
|
||
vertical: 26.rpx,
|
||
horizontal: 10.rpx),
|
||
isDense: true,
|
||
hintText: '未命名'.tr,
|
||
hintStyle: TextStyle(
|
||
fontFamily: 'Inter',
|
||
fontSize: 26.rpx,
|
||
color: themeController
|
||
.currentColor.sc4,
|
||
),
|
||
enabledBorder:
|
||
OutlineInputBorder(
|
||
borderSide: BorderSide(
|
||
color:
|
||
Colors.transparent,
|
||
width: 1.rpx),
|
||
borderRadius:
|
||
BorderRadius.circular(
|
||
8.rpx),
|
||
),
|
||
focusedBorder:
|
||
OutlineInputBorder(
|
||
borderSide: BorderSide(
|
||
color:
|
||
Colors.transparent,
|
||
width: 1.rpx),
|
||
borderRadius:
|
||
BorderRadius.circular(
|
||
8.rpx),
|
||
),
|
||
errorBorder:
|
||
OutlineInputBorder(
|
||
borderSide: BorderSide(
|
||
width: 1.rpx),
|
||
borderRadius:
|
||
BorderRadius.circular(
|
||
8.rpx),
|
||
),
|
||
focusedErrorBorder:
|
||
OutlineInputBorder(
|
||
borderSide: BorderSide(
|
||
width: 1.rpx),
|
||
borderRadius:
|
||
BorderRadius.circular(
|
||
8.rpx),
|
||
),
|
||
filled: false,
|
||
),
|
||
style: TextStyle(
|
||
fontFamily: 'Inter',
|
||
fontSize: 30.rpx,
|
||
color: themeController
|
||
.currentColor.sc3,
|
||
height: 1.0, // 防止偏移
|
||
),
|
||
cursorColor: themeController
|
||
.currentColor.sc3,
|
||
),
|
||
),
|
||
),
|
||
].divide(SizedBox(width: 27.rpx)),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
Padding(
|
||
padding: EdgeInsets.only(
|
||
left: 0.rpx, right: 0.rpx, bottom: 85.rpx),
|
||
child: CustomCard(
|
||
borderRadius: 10.rpx,
|
||
onTap: () async {
|
||
ApiResponse apiResponse =
|
||
await userInfoController.updateData();
|
||
TopSlideNotification.show(
|
||
context,
|
||
text: apiResponse.msg!,
|
||
textColor: apiResponse.code == HttpStatusCodes.ok
|
||
? themeController.currentColor.sc2
|
||
: themeController.currentColor.sc9,
|
||
);
|
||
if (apiResponse.code == HttpStatusCodes.ok) {
|
||
userInfoController.model.user!.tmpHead = null;
|
||
userInfoController.model.user!.tmpNickName = null;
|
||
await userInfoController.getUserInfo();
|
||
userInfoController.model.user!.tmpNickName =
|
||
userInfoController.model.user!.nick_name;
|
||
userInfoController.model.user!.tmpHead =
|
||
userInfoController.model.user!.avatar;
|
||
userInfoController.updateAll();
|
||
Get.back();
|
||
}
|
||
},
|
||
colors: [
|
||
stringToColor("FCFCFC"),
|
||
stringToColor("CEECE3"),
|
||
],
|
||
gradientDirection: GradientDirection.vertical,
|
||
child: Container(
|
||
// width: 100.rpx,
|
||
height: 90.rpx,
|
||
alignment: Alignment.center,
|
||
padding: EdgeInsetsDirectional.fromSTEB(
|
||
16.rpx, 0.rpx, 16.rpx, 0.rpx),
|
||
child: Text(
|
||
'保存'.tr,
|
||
style: TextStyle(
|
||
fontFamily: 'Inter Tight',
|
||
color: stringToColor("#011D33"),
|
||
letterSpacing: 0.0,
|
||
fontSize:
|
||
AppConstants().normal_text_fontSize),
|
||
),
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget getImageWidget(BuildContext context) {
|
||
try {
|
||
UserInfoController controller = Get.find();
|
||
var head = controller.model.user!.tmpHead;
|
||
return Container(
|
||
width: 200.rpx,
|
||
height: 200.rpx,
|
||
child: Container(
|
||
clipBehavior: Clip.antiAlias,
|
||
decoration: BoxDecoration(
|
||
shape: BoxShape.circle,
|
||
),
|
||
child: head == null || head.isEmpty
|
||
? Image.asset(
|
||
'assets/img/avatar.png',
|
||
fit: BoxFit.cover,
|
||
)
|
||
: Image.network(
|
||
head,
|
||
fit: BoxFit.cover,
|
||
),
|
||
),
|
||
);
|
||
} catch (e) {
|
||
print(e);
|
||
}
|
||
return Container();
|
||
}
|
||
}
|