2023-10-13 15:12:03 +08:00

205 lines
7.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_logic.dart';
import 'package:star_lock/tools/custom_bottom_sheet.dart';
import '../../../appRouters.dart';
import '../../../tools/commonItem.dart';
import '../../../tools/titleAppBar.dart';
import '../../../translations/trans_lib.dart';
class MinePersonInfoPage extends StatefulWidget {
const MinePersonInfoPage({Key? key}) : super(key: key);
@override
State<MinePersonInfoPage> createState() => _MinePersonInfoPageState();
}
class _MinePersonInfoPageState extends State<MinePersonInfoPage> {
final logic = Get.put(MinePersonInfoLogic());
final state = Get.find<MinePersonInfoLogic>().state;
@override
void initState() {
super.initState();
logic.getUserInfoRequest();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.personalInformation!.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Column(
children: [
CommonItem(
leftTitel: TranslationLoader.lanKeys!.avatar!.tr,
rightTitle: "",
allHeight: 100.h,
isHaveLine: true,
isHaveDirection: true,
isHaveRightWidget: true,
rightWidget: ClipOval(
child: state.image != null
? Image.file(
File(state.image!.path),
width: 72.w,
height: 72.w,
fit: BoxFit.fill,
)
: Image.asset(
'images/controls_user.png',
width: 72.w,
height: 72.w,
fit: BoxFit.fill,
),
),
action: () {
_openModalBottomSheet();
},
),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.nickName!.tr,
rightTitle: state.nickname.value,
isHaveLine: true,
isHaveDirection: true,
action: () {
Navigator.pushNamed(
context, Routers.minePersonInfoEditNamePage,
arguments: {'nickName': state.nickname.value})
.then((value) => logic.getUserInfoRequest());
})),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.mobileNumber!.tr,
rightTitle: state.mobileStr.value.isNotEmpty
? state.mobileStr.value
: TranslationLoader.lanKeys!.goBind!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
//有手机号 则去修改手机号 否则去绑定新的手机号 isFrom1 短信2 邮箱
if (state.mobileStr.value.isNotEmpty) {
Navigator.pushNamed(
context, Routers.mineUnbindPhoneOrEmailPage,
arguments: {
'mobile': state.mobileStr.value,
'isFrom': '1'
}).then((value) => logic.getUserInfoRequest());
} else {
Navigator.pushNamed(
context, Routers.mineBindPhoneOrEmailPage, arguments: {
'mobile': state.mobileStr.value,
'isFrom': '1'
}).then((value) => logic.getUserInfoRequest());
}
})),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.email!.tr,
rightTitle: state.emailStr.value.isNotEmpty
? state.emailStr.value
: TranslationLoader.lanKeys!.goBind!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
//有邮箱 则去修改邮箱 否则去绑定新的邮箱 isFrom1 短信2 邮箱
if (state.emailStr.value.isNotEmpty) {
Navigator.pushNamed(
context, Routers.mineUnbindPhoneOrEmailPage,
arguments: {
'isFrom': '2',
'email': state.emailStr.value
}).then((value) => logic.getUserInfoRequest());
} else {
Navigator.pushNamed(
context, Routers.mineBindPhoneOrEmailPage, arguments: {
'isFrom': '2',
'email': state.emailStr.value
}).then((value) => logic.getUserInfoRequest());
}
})),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.resetPasswords!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Navigator.pushNamed(
context, Routers.minePersonInfoResetPasswordPage);
}),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.safetyProblem!.tr,
rightTitle: state.haveSafeAnswer.value == 0 ? "去设置" : "",
isHaveLine: true,
isHaveDirection: true,
action: () {
if (state.haveSafeAnswer.value == 0) {
Navigator.pushNamed(
context, Routers.minePersonInfoSetSafetyProblemPage)
.then((value) => logic.getUserInfoRequest());
} else {
Navigator.pushNamed(
context, Routers.minePersonInfoViewSafetyProblemPage);
}
})),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.countryAndRegion!.tr,
rightTitle: state.countryStr.value,
isHaveLine: false,
isHaveDirection: false)),
],
));
}
Future _openModalBottomSheet() async {
showModalBottomSheet(
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(10)),
builder: (BuildContext context) {
return AlertBottomWidget(
topTitle: '',
items: const ['拍照', '从相册选择'],
chooseCallback: (value) {
int getSelectIndex = value;
if (getSelectIndex == 0) {
//拍照选项
selectCamera();
} else if (getSelectIndex == 1) {
selectImage();
}
},
);
});
}
///拍摄照片
selectCamera() async {
XFile? photo = await state.imagePicker.pickImage(
source: ImageSource.camera, preferredCameraDevice: CameraDevice.rear);
if (photo != null) {
state.image = photo;
// logic.getUpTokenRequest();
setState(() {});
}
}
///从相册选取
selectImage() async {
XFile? image = await state.imagePicker.pickImage(
source: ImageSource.gallery,
maxHeight: 250,
maxWidth: 250,
);
if (image != null) state.image = image;
setState(() {});
}
}