|
|
|
@ -20,6 +20,8 @@ import 'package:permission_handler/permission_handler.dart';
|
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart'; |
|
|
|
|
|
|
|
|
|
import '../view_widget/request_permission.dart'; |
|
|
|
|
|
|
|
|
|
class UserInfoPage extends StatefulWidget { |
|
|
|
|
@override |
|
|
|
|
State<StatefulWidget> createState() { |
|
|
|
@ -391,7 +393,41 @@ class _UserInfoPage extends State<UserInfoPage> {
|
|
|
|
|
|
|
|
|
|
///拍照 |
|
|
|
|
openCamera() async { |
|
|
|
|
if (await Permission.camera.isGranted) { |
|
|
|
|
if (await Permission.camera.isPermanentlyDenied) { |
|
|
|
|
showCupertinoDialog( |
|
|
|
|
context: context, |
|
|
|
|
builder: (context) { |
|
|
|
|
return RequestPermission( |
|
|
|
|
"assets/image/icon_camera_permission_tips.webp", |
|
|
|
|
S.of(context).ninxiangjiquanxianweikaiqi, |
|
|
|
|
S.of(context).weilekaipaizhaoxuanzhetouxiang, |
|
|
|
|
S.of(context).kaiqiquanxian, |
|
|
|
|
(result) async { |
|
|
|
|
if (result) { |
|
|
|
|
await openAppSettings(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
heightRatioWithWidth: 0.82, |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
}else if (await Permission.camera.isGranted) { |
|
|
|
|
if (await Permission.storage.isPermanentlyDenied) { |
|
|
|
|
showCupertinoDialog( |
|
|
|
|
context: context, |
|
|
|
|
builder: (context) { |
|
|
|
|
return RequestPermission( |
|
|
|
|
"assets/image/icon_storage_permission_tips.webp", |
|
|
|
|
"您未开启存储权限,请点击开启", |
|
|
|
|
"为了您可以在使用过程中访问您设备上的照片、媒体内容和文件,请您开启存储使用权限", |
|
|
|
|
S.of(context).kaiqiquanxian, |
|
|
|
|
(result) async { |
|
|
|
|
if (result) { |
|
|
|
|
await openAppSettings(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
heightRatioWithWidth: 0.82, |
|
|
|
|
); |
|
|
|
|
});}else if(await Permission.storage.isGranted){ |
|
|
|
|
Media medias = await ImagePickers.openCamera( |
|
|
|
|
cameraMimeType: CameraMimeType.photo, |
|
|
|
|
cropConfig: CropConfig( |
|
|
|
@ -404,9 +440,15 @@ class _UserInfoPage extends State<UserInfoPage> {
|
|
|
|
|
if (medias == null) return; |
|
|
|
|
filePath = medias.path; |
|
|
|
|
fileUpload(); |
|
|
|
|
}else{ |
|
|
|
|
showStorageTipsAlertDialog(context,1); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
await Permission.camera.request(); |
|
|
|
|
openCamera(); |
|
|
|
|
showCameraTipsAlertDialog(context); |
|
|
|
|
return false; |
|
|
|
|
// await Permission.camera.request(); |
|
|
|
|
// openCamera(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -414,7 +456,24 @@ class _UserInfoPage extends State<UserInfoPage> {
|
|
|
|
|
|
|
|
|
|
///打开相册 |
|
|
|
|
openStorage() async { |
|
|
|
|
if (await Permission.storage.isGranted) { |
|
|
|
|
if (await Permission.storage.isPermanentlyDenied) { |
|
|
|
|
showCupertinoDialog( |
|
|
|
|
context: context, |
|
|
|
|
builder: (context) { |
|
|
|
|
return RequestPermission( |
|
|
|
|
"assets/image/icon_storage_permission_tips.webp", |
|
|
|
|
"您未开启存储权限,请点击开启", |
|
|
|
|
"为了您可以在使用过程中访问您设备上的照片、媒体内容和文件,请您开启存储使用权限", |
|
|
|
|
S.of(context).kaiqiquanxian, |
|
|
|
|
(result) async { |
|
|
|
|
if (result) { |
|
|
|
|
await openAppSettings(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
heightRatioWithWidth: 0.82, |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
}else if (await Permission.storage.isGranted) { |
|
|
|
|
List<Media> medias = await ImagePickers.pickerPaths( |
|
|
|
|
galleryMode: GalleryMode.image, |
|
|
|
|
selectCount: 1, |
|
|
|
@ -435,10 +494,156 @@ class _UserInfoPage extends State<UserInfoPage> {
|
|
|
|
|
setState(() {}); |
|
|
|
|
fileUpload(); |
|
|
|
|
} else { |
|
|
|
|
showStorageTipsAlertDialog(context,0); |
|
|
|
|
return false; |
|
|
|
|
// await Permission.storage.request(); |
|
|
|
|
// openStorage(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///相册权限说明 |
|
|
|
|
showStorageTipsAlertDialog(context,type) async { |
|
|
|
|
//显示对话框 |
|
|
|
|
showDialog( |
|
|
|
|
context: context, |
|
|
|
|
barrierDismissible: false, |
|
|
|
|
barrierColor: null, |
|
|
|
|
builder: (BuildContext context) { |
|
|
|
|
return Column( |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
width: double.infinity, |
|
|
|
|
padding: EdgeInsets.all(15), |
|
|
|
|
margin: EdgeInsets.all(15), |
|
|
|
|
decoration: new BoxDecoration( |
|
|
|
|
color: Colors.white, |
|
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Padding(padding:EdgeInsets.only(right: 10.w,), |
|
|
|
|
child: Icon( |
|
|
|
|
Icons.add_photo_alternate_outlined, |
|
|
|
|
color: Colors.black, |
|
|
|
|
size: 22, |
|
|
|
|
)), |
|
|
|
|
Expanded( |
|
|
|
|
child: Column( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
"存储权限使用说明", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 18.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
SizedBox( |
|
|
|
|
height: 3.h, |
|
|
|
|
), |
|
|
|
|
Text( |
|
|
|
|
"为了帮您实现分享照片、保存照片等功能。", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 13.sp, |
|
|
|
|
height: 1.2, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
await Permission.storage.request(); |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
if(await Permission.storage.isGranted){ |
|
|
|
|
if(type == 1){ |
|
|
|
|
openCamera(); |
|
|
|
|
}else{ |
|
|
|
|
openStorage(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
///拍照权限说明 |
|
|
|
|
showCameraTipsAlertDialog(context) async { |
|
|
|
|
//显示对话框 |
|
|
|
|
showDialog( |
|
|
|
|
context: context, |
|
|
|
|
barrierDismissible: false, |
|
|
|
|
barrierColor: null, |
|
|
|
|
builder: (BuildContext context) { |
|
|
|
|
return Column( |
|
|
|
|
children: [ |
|
|
|
|
Container( |
|
|
|
|
width: double.infinity, |
|
|
|
|
padding: EdgeInsets.all(15), |
|
|
|
|
margin: EdgeInsets.all(15), |
|
|
|
|
decoration: new BoxDecoration( |
|
|
|
|
color: Colors.white, |
|
|
|
|
borderRadius: BorderRadius.circular(10), |
|
|
|
|
), |
|
|
|
|
child: Row( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
children: [ |
|
|
|
|
Padding(padding:EdgeInsets.only(right: 10.w,), |
|
|
|
|
child: Icon( |
|
|
|
|
Icons.add_photo_alternate_outlined, |
|
|
|
|
color: Colors.black, |
|
|
|
|
size: 22, |
|
|
|
|
)), |
|
|
|
|
Expanded( |
|
|
|
|
child: Column( |
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
|
children: [ |
|
|
|
|
Text( |
|
|
|
|
"相机权限使用说明", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 18.sp, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
SizedBox( |
|
|
|
|
height: 3.h, |
|
|
|
|
), |
|
|
|
|
Text( |
|
|
|
|
"实现您扫码、拍摄等功能。", |
|
|
|
|
style: TextStyle( |
|
|
|
|
fontSize: 13.sp, |
|
|
|
|
height: 1.2, |
|
|
|
|
fontWeight: MyFontWeight.regular, |
|
|
|
|
color: Colors.black, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
), |
|
|
|
|
) |
|
|
|
|
], |
|
|
|
|
mainAxisSize: MainAxisSize.min, |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
await Permission.camera.request(); |
|
|
|
|
Navigator.of(context).pop(); |
|
|
|
|
if(await Permission.camera.isGranted){ |
|
|
|
|
openCamera(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Future<File> cropImage(imagePath) async { |
|
|
|
|
// File croppedFile = await ImageCropper.cropImage( |
|
|
|
|