修复上架审核出现的拒绝相机权限后无法使用头像功能问题

This commit is contained in:
Daisy 2024-03-13 15:51:54 +08:00
parent e078a67af5
commit 21854e97a1
4 changed files with 97 additions and 56 deletions

View File

@ -30,7 +30,6 @@
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<!--允许麦克风权限,用于录音发送-->
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

View File

@ -64,7 +64,7 @@ post_install do |installer|
# 'PERMISSION_CONTACTS=1',
## dart: PermissionGroup.camera
# 'PERMISSION_CAMERA=1',
'PERMISSION_CAMERA=1',
## dart: PermissionGroup.microphone
# 'PERMISSION_MICROPHONE=1',
@ -73,7 +73,7 @@ post_install do |installer|
# 'PERMISSION_SPEECH_RECOGNIZER=1',
## dart: PermissionGroup.photos
# 'PERMISSION_PHOTOS=1',
'PERMISSION_PHOTOS=1',
# dart: [PermissionGroup.location, PermissionGroup.locationAlways, PermissionGroup.locationWhenInUse]
'PERMISSION_LOCATION=1',

View File

@ -43,48 +43,42 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage> {
backgroundColor: AppColors.mainColor),
body: Column(
children: [
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: () async {
//
if (Platform.isAndroid) {
AppFirstEnterHandle()
.getAppFirstEnter(context, isAgreeCamera);
var getFlag = await Storage.getString(isAgreeCamera);
if (getFlag == isAgreeCamera) {
requestCameraPermission();
}
} else {
requestCameraPermission();
}
},
)),
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: () async {
//
if (Platform.isAndroid) {
AppFirstEnterHandle()
.getAppFirstEnter(context, isAgreeCamera);
var getFlag = await Storage.getString(isAgreeCamera);
if (getFlag == isAgreeCamera) {
_openModalBottomSheet();
}
} else {
_openModalBottomSheet();
}
},
),
Obx(() => CommonItem(
leftTitel: TranslationLoader.lanKeys!.nickName!.tr,
rightTitle: state.mineInfoData.value.nickname != null
@ -189,7 +183,7 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage> {
if (status.isGranted) {
//
//
_openModalBottomSheet();
selectCamera();
} else {
//
//
@ -197,28 +191,53 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage> {
if (status.isGranted) {
//
_openModalBottomSheet();
selectCamera();
} else {
//
//
_showPermissinDialog();
showPermissionDeniedDialog();
}
}
}
Future _showPermissinDialog() async {
Future<void> requestPhotoPermission() async {
//
PermissionStatus status = await Permission.photos.status;
if (status.isGranted) {
//
//
selectImage();
} else {
//
//
status = await Permission.photos.request();
if (status.isGranted) {
//
selectImage();
} else {
//
//
showPermissionDeniedDialog();
}
}
}
//
void showPermissionDeniedDialog() {
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.'),
title: const Text('权限被拒绝'),
content: const Text('请手动在系统设置中开启相册权限以继续使用应用。'),
actions: <Widget>[
TextButton(
child: const Text('OK'),
child: const Text('去设置'),
onPressed: () {
Navigator.of(context).pop();
openAppSettings(); //
Navigator.of(context).pop(); //
},
),
],
@ -240,9 +259,11 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage> {
int getSelectIndex = value;
if (getSelectIndex == 0) {
//
selectCamera();
// selectCamera();
requestCameraPermission();
} else if (getSelectIndex == 1) {
selectImage();
// selectImage();
requestPhotoPermission();
}
},
);
@ -278,4 +299,24 @@ class _MinePersonInfoPageState extends State<MinePersonInfoPage> {
setState(() {});
}
}
// 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,
// ),
}

View File

@ -140,6 +140,7 @@ dependencies:
#侧滑删除
flutter_slidable: ^3.0.1
audio_service: ^0.18.12
app_settings: ^5.1.1
system_settings: ^2.0.0
dev_dependencies: