fix:用户头像上传,相册上传针对andriud33以下的设备兼容

This commit is contained in:
anfe 2024-04-09 10:52:30 +08:00
parent 2447cb43dc
commit 98b6a23d4f

View File

@ -7,6 +7,7 @@ import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:star_lock/app_settings/app_colors.dart'; import 'package:star_lock/app_settings/app_colors.dart';
import 'package:star_lock/app_settings/app_settings.dart';
import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_logic.dart'; import 'package:star_lock/mine/minePersonInfo/minePersonInfoPage/minePersonInfo_logic.dart';
import 'package:star_lock/tools/appFirstEnterHandle.dart'; import 'package:star_lock/tools/appFirstEnterHandle.dart';
import 'package:star_lock/tools/custom_bottom_sheet.dart'; import 'package:star_lock/tools/custom_bottom_sheet.dart';
@ -23,8 +24,7 @@ class MinePersonInfoPage extends StatefulWidget {
State<MinePersonInfoPage> createState() => _MinePersonInfoPageState(); State<MinePersonInfoPage> createState() => _MinePersonInfoPageState();
} }
class _MinePersonInfoPageState extends State<MinePersonInfoPage> class _MinePersonInfoPageState extends State<MinePersonInfoPage> with WidgetsBindingObserver {
with WidgetsBindingObserver {
final logic = Get.put(MinePersonInfoLogic()); final logic = Get.put(MinePersonInfoLogic());
final state = Get.find<MinePersonInfoLogic>().state; final state = Get.find<MinePersonInfoLogic>().state;
@ -88,8 +88,7 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
action: () async { action: () async {
// //
if (Platform.isAndroid) { if (Platform.isAndroid) {
AppFirstEnterHandle() AppFirstEnterHandle().getAppFirstEnter(context, isAgreeCamera);
.getAppFirstEnter(context, isAgreeCamera);
var getFlag = await Storage.getString(isAgreeCamera); var getFlag = await Storage.getString(isAgreeCamera);
if (getFlag == isAgreeCamera) { if (getFlag == isAgreeCamera) {
_openModalBottomSheet(); _openModalBottomSheet();
@ -101,16 +100,13 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
), ),
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.nickName!.tr, leftTitel: TranslationLoader.lanKeys!.nickName!.tr,
rightTitle: state.mineInfoData.value.nickname != null rightTitle: state.mineInfoData.value.nickname != null ? state.mineInfoData.value.nickname! : "",
? state.mineInfoData.value.nickname!
: "",
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Navigator.pushNamed( Navigator.pushNamed(context, Routers.minePersonInfoEditNamePage,
context, Routers.minePersonInfoEditNamePage, arguments: { arguments: {'nickName': state.mineInfoData.value.nickname})
'nickName': state.mineInfoData.value.nickname .then((value) => logic.getUserInfoRequest());
}).then((value) => logic.getUserInfoRequest());
})), })),
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.mobileNumber!.tr, leftTitel: TranslationLoader.lanKeys!.mobileNumber!.tr,
@ -122,16 +118,13 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
action: () { action: () {
// isFrom1 2 // isFrom1 2
if (state.mineInfoData.value.mobile!.isNotEmpty) { if (state.mineInfoData.value.mobile!.isNotEmpty) {
Navigator.pushNamed(context, Routers.mineUnbindPhoneOrEmailPage, arguments: { Navigator.pushNamed(context, Routers.mineUnbindPhoneOrEmailPage,
'mobile': state.mineInfoData.value.mobile!, arguments: {'mobile': state.mineInfoData.value.mobile!, 'isFrom': '1'})
'isFrom': '1' .then((value) => logic.getUserInfoRequest());
}).then((value) => logic.getUserInfoRequest());
} else { } else {
Navigator.pushNamed( Navigator.pushNamed(context, Routers.mineBindPhoneOrEmailPage,
context, Routers.mineBindPhoneOrEmailPage, arguments: { arguments: {'mobile': state.mineInfoData.value.mobile!, 'isFrom': '1'})
'mobile': state.mineInfoData.value.mobile!, .then((value) => logic.getUserInfoRequest());
'isFrom': '1'
}).then((value) => logic.getUserInfoRequest());
} }
})), })),
Obx(() => CommonItem( Obx(() => CommonItem(
@ -144,18 +137,13 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
action: () { action: () {
// isFrom1 2 // isFrom1 2
if (state.mineInfoData.value.email!.isNotEmpty) { if (state.mineInfoData.value.email!.isNotEmpty) {
Navigator.pushNamed( Navigator.pushNamed(context, Routers.mineUnbindPhoneOrEmailPage,
context, Routers.mineUnbindPhoneOrEmailPage, arguments: {'isFrom': '2', 'email': state.mineInfoData.value.email!})
arguments: { .then((value) => logic.getUserInfoRequest());
'isFrom': '2',
'email': state.mineInfoData.value.email!
}).then((value) => logic.getUserInfoRequest());
} else { } else {
Navigator.pushNamed( Navigator.pushNamed(context, Routers.mineBindPhoneOrEmailPage,
context, Routers.mineBindPhoneOrEmailPage, arguments: { arguments: {'isFrom': '2', 'email': state.mineInfoData.value.email!})
'isFrom': '2', .then((value) => logic.getUserInfoRequest());
'email': state.mineInfoData.value.email!
}).then((value) => logic.getUserInfoRequest());
} }
})), })),
CommonItem( CommonItem(
@ -164,30 +152,24 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
Navigator.pushNamed( Navigator.pushNamed(context, Routers.minePersonInfoResetPasswordPage);
context, Routers.minePersonInfoResetPasswordPage);
}), }),
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.safetyProblem!.tr, leftTitel: TranslationLoader.lanKeys!.safetyProblem!.tr,
rightTitle: rightTitle: state.mineInfoData.value.haveSafeAnswer == 0 ? "去设置" : "",
state.mineInfoData.value.haveSafeAnswer == 0 ? "去设置" : "",
isHaveLine: true, isHaveLine: true,
isHaveDirection: true, isHaveDirection: true,
action: () { action: () {
if (state.mineInfoData.value.haveSafeAnswer == 0) { if (state.mineInfoData.value.haveSafeAnswer == 0) {
Navigator.pushNamed( Navigator.pushNamed(context, Routers.minePersonInfoSetSafetyProblemPage)
context, Routers.minePersonInfoSetSafetyProblemPage)
.then((value) => logic.getUserInfoRequest()); .then((value) => logic.getUserInfoRequest());
} else { } else {
Navigator.pushNamed( Navigator.pushNamed(context, Routers.minePersonInfoViewSafetyProblemPage);
context, Routers.minePersonInfoViewSafetyProblemPage);
} }
})), })),
Obx(() => CommonItem( Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.countryAndRegion!.tr, leftTitel: TranslationLoader.lanKeys!.countryAndRegion!.tr,
rightTitle: state.mineInfoData.value.countryName != null rightTitle: state.mineInfoData.value.countryName != null ? state.mineInfoData.value.countryName! : "",
? state.mineInfoData.value.countryName!
: "",
isHaveLine: false, isHaveLine: false,
isHaveDirection: false)), isHaveDirection: false)),
], ],
@ -221,7 +203,9 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
} }
Future<void> _requestPhotoPermission() async { Future<void> _requestPhotoPermission() async {
var status = await Permission.photos.request(); //andriud33以下的设备兼容
bool isAndroid33 = AppPlatform.isAndroid && AppPlatform.getSdkIntValue() >= 33;
var status = isAndroid33 ? await Permission.photos.request() : await Permission.storage.request();
if (status.isGranted) { if (status.isGranted) {
setState(() { setState(() {
state.hasPhotoPermission.value = true; // state.hasPhotoPermission.value = true; //
@ -271,8 +255,7 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
Future _openModalBottomSheet() async { Future _openModalBottomSheet() async {
showModalBottomSheet( showModalBottomSheet(
context: context, context: context,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(borderRadius: BorderRadiusDirectional.circular(10)),
borderRadius: BorderRadiusDirectional.circular(10)),
builder: (BuildContext context) { builder: (BuildContext context) {
return AlertBottomWidget( return AlertBottomWidget(
topTitle: '', topTitle: '',
@ -281,13 +264,9 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
int getSelectIndex = value; int getSelectIndex = value;
if (getSelectIndex == 0) { if (getSelectIndex == 0) {
// //
state.hasCameraPermission.value == true state.hasCameraPermission.value == true ? selectCamera() : _requestCameraPermission();
? selectCamera()
: _requestCameraPermission();
} else if (getSelectIndex == 1) { } else if (getSelectIndex == 1) {
state.hasPhotoPermission.value == true state.hasPhotoPermission.value == true ? selectImage() : _requestPhotoPermission();
? selectImage()
: _requestPhotoPermission();
} }
}, },
); );
@ -296,8 +275,8 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage>
/// ///
selectCamera() async { selectCamera() async {
XFile? photo = await state.imagePicker.pickImage( XFile? photo =
source: ImageSource.camera, preferredCameraDevice: CameraDevice.rear); await state.imagePicker.pickImage(source: ImageSource.camera, preferredCameraDevice: CameraDevice.rear);
if (photo != null) { if (photo != null) {
state.image = photo; state.image = photo;
// logic.getUpTokenRequest(); // logic.getUpTokenRequest();