205 lines
7.6 KiB
Dart
Raw Normal View History

import 'dart:io';
2023-07-18 18:10:57 +08:00
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';
2023-07-18 18:10:57 +08:00
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';
2023-07-18 18:10:57 +08:00
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();
}
2023-07-18 18:10:57 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.mainBackgroundColor,
appBar: TitleAppBar(
barTitle: TranslationLoader.lanKeys!.personalInformation!.tr,
haveBack: true,
backgroundColor: AppColors.mainColor),
body: Column(
2023-07-18 18:10:57 +08:00
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,
2023-10-09 18:52:42 +08:00
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'
2023-10-13 15:12:03 +08:00
}).then((value) => logic.getUserInfoRequest());
} else {
Navigator.pushNamed(
context, Routers.mineBindPhoneOrEmailPage, arguments: {
'mobile': state.mobileStr.value,
'isFrom': '1'
2023-10-13 15:12:03 +08:00
}).then((value) => logic.getUserInfoRequest());
}
})),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.email!.tr,
2023-10-09 18:52:42 +08:00
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
2023-10-13 15:12:03 +08:00
}).then((value) => logic.getUserInfoRequest());
} else {
Navigator.pushNamed(
context, Routers.mineBindPhoneOrEmailPage, arguments: {
'isFrom': '2',
'email': state.emailStr.value
2023-10-13 15:12:03 +08:00
}).then((value) => logic.getUserInfoRequest());
}
})),
CommonItem(
leftTitel: TranslationLoader.lanKeys!.resetPasswords!.tr,
rightTitle: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Navigator.pushNamed(
context, Routers.minePersonInfoResetPasswordPage);
}),
2023-10-13 15:12:03 +08:00
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);
}
2023-10-13 15:12:03 +08:00
})),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.countryAndRegion!.tr,
rightTitle: state.countryStr.value,
isHaveLine: false,
isHaveDirection: false)),
2023-07-18 18:10:57 +08:00
],
));
2023-07-18 18:10:57 +08:00
}
Future _openModalBottomSheet() async {
showModalBottomSheet(
2023-07-18 18:10:57 +08:00
context: context,
shape: RoundedRectangleBorder(
borderRadius: BorderRadiusDirectional.circular(10)),
2023-07-18 18:10:57 +08:00
builder: (BuildContext context) {
return AlertBottomWidget(
topTitle: '',
items: const ['拍照', '从相册选择'],
chooseCallback: (value) {
int getSelectIndex = value;
if (getSelectIndex == 0) {
//拍照选项
selectCamera();
} else if (getSelectIndex == 1) {
selectImage();
}
},
2023-07-18 18:10:57 +08:00
);
});
2023-07-18 18:10:57 +08:00
}
///拍摄照片
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(() {});
}
2023-07-18 18:10:57 +08:00
}