270 lines
10 KiB
Dart
Raw Normal View History

import 'dart:io';
2024-03-05 09:29:49 +08:00
import 'package:cached_network_image/cached_network_image.dart';
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';
2024-03-07 17:59:22 +08:00
import 'package:permission_handler/permission_handler.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;
2024-03-05 09:29:49 +08:00
@override
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: [
2024-03-05 09:29:49 +08:00
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.avatar!.tr,
rightTitle: "",
allHeight: 100.h,
isHaveLine: true,
isHaveDirection: true,
isHaveRightWidget: true,
rightWidget: ClipOval(
child: state.mineInfoData.value.headUrl != null
? CachedNetworkImage(
imageUrl: Uri.encodeFull(
state.mineInfoData.value.headUrl!),
width: 72.w,
height: 72.w,
fit: BoxFit.fill,
placeholder: (context, url) => Image.asset(
'images/controls_user.png',
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: () {
2024-03-07 17:59:22 +08:00
requestCameraPermission();
2024-03-05 09:29:49 +08:00
},
)),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.nickName!.tr,
2024-03-05 09:29:49 +08:00
rightTitle: state.mineInfoData.value.nickname != null
? state.mineInfoData.value.nickname!
: "",
isHaveLine: true,
isHaveDirection: true,
action: () {
Navigator.pushNamed(
2024-03-05 09:29:49 +08:00
context, Routers.minePersonInfoEditNamePage, arguments: {
'nickName': state.mineInfoData.value.nickname
}).then((value) => logic.getUserInfoRequest());
})),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.mobileNumber!.tr,
2024-03-05 09:29:49 +08:00
rightTitle: state.mineInfoData.value.mobile != null
? state.mineInfoData.value.mobile!
2023-10-09 18:52:42 +08:00
: TranslationLoader.lanKeys!.goBind!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
//有手机号 则去修改手机号 否则去绑定新的手机号 isFrom1 短信2 邮箱
2024-03-05 09:29:49 +08:00
if (state.mineInfoData.value.mobile!.isNotEmpty) {
Navigator.pushNamed(
context, Routers.mineUnbindPhoneOrEmailPage,
arguments: {
2024-03-05 09:29:49 +08:00
'mobile': state.mineInfoData.value.mobile!,
'isFrom': '1'
2023-10-13 15:12:03 +08:00
}).then((value) => logic.getUserInfoRequest());
} else {
Navigator.pushNamed(
context, Routers.mineBindPhoneOrEmailPage, arguments: {
2024-03-05 09:29:49 +08:00
'mobile': state.mineInfoData.value.mobile!,
'isFrom': '1'
2023-10-13 15:12:03 +08:00
}).then((value) => logic.getUserInfoRequest());
}
})),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.email!.tr,
2024-03-05 09:29:49 +08:00
rightTitle: state.mineInfoData.value.email != null
? state.mineInfoData.value.email!
2023-10-09 18:52:42 +08:00
: TranslationLoader.lanKeys!.goBind!.tr,
isHaveLine: true,
isHaveDirection: true,
action: () {
//有邮箱 则去修改邮箱 否则去绑定新的邮箱 isFrom1 短信2 邮箱
2024-03-05 09:29:49 +08:00
if (state.mineInfoData.value.email!.isNotEmpty) {
Navigator.pushNamed(
context, Routers.mineUnbindPhoneOrEmailPage,
arguments: {
'isFrom': '2',
2024-03-05 09:29:49 +08:00
'email': state.mineInfoData.value.email!
2023-10-13 15:12:03 +08:00
}).then((value) => logic.getUserInfoRequest());
} else {
Navigator.pushNamed(
context, Routers.mineBindPhoneOrEmailPage, arguments: {
'isFrom': '2',
2024-03-05 09:29:49 +08:00
'email': state.mineInfoData.value.email!
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,
2024-03-05 09:29:49 +08:00
rightTitle:
state.mineInfoData.value.haveSafeAnswer == 0 ? "去设置" : "",
isHaveLine: true,
isHaveDirection: true,
action: () {
2024-03-05 09:29:49 +08:00
if (state.mineInfoData.value.haveSafeAnswer == 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,
2024-03-05 09:29:49 +08:00
rightTitle: state.mineInfoData.value.countryName != null
? state.mineInfoData.value.countryName!
: "",
isHaveLine: false,
isHaveDirection: false)),
2023-07-18 18:10:57 +08:00
],
));
2023-07-18 18:10:57 +08:00
}
2024-03-07 17:59:22 +08:00
Future<void> requestCameraPermission() async {
// 检查是否已经授予相机权限
PermissionStatus status = await Permission.camera.status;
if (status.isGranted) {
// 如果权限已经被授予,执行您的相机操作
// 这里可以调用打开相机的方法或者跳转到相机页面等
_openModalBottomSheet();
} else {
// 如果权限尚未被授予,请求相机权限
// 此处会显示系统权限请求对话框
status = await Permission.camera.request();
if (status.isGranted) {
// 如果用户授予了相机权限,执行您的相机操作
_openModalBottomSheet();
} else {
// 如果用户拒绝了相机权限,您可以提供适当的提示
// 或者引导用户手动授予权限
_showPermissinDialog();
}
}
}
Future _showPermissinDialog() async {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Permission Required'),
content: const Text(
'You need to grant camera permission to use this feature.'),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}
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;
var bytes = File(state.image!.path);
var enc = await bytes.readAsBytes();
print(enc.length);
2024-03-05 09:29:49 +08:00
print(
"state.image!.path:${state.image!.path} state.image!.name:${state.image!.name} state.image!.length():${state.image!.length()}");
logic.getUpTokenRequest(state.image!.name, enc.length);
2024-03-05 09:29:49 +08:00
setState(() {});
}
}
2023-07-18 18:10:57 +08:00
}