From 113bcd15ef8d563071773fc051ce72c54130818b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cyanghuaxuan=E2=80=9D?= <“646903573@qq.com”> Date: Sat, 24 Apr 2021 18:01:13 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=9B=B4=E6=96=B0=E6=9D=83=E9=99=90=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=BC=B9=E7=AA=97=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notification_setting_dialog.dart | 17 +- .../mine_detail_page/mine_detail_page.dart | 181 ++++++++++-------- .../upload_wechat_page.dart | 14 +- 3 files changed, 126 insertions(+), 86 deletions(-) diff --git a/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart b/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart index 2d8293a..c3fc4a7 100644 --- a/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart +++ b/lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart @@ -219,6 +219,17 @@ class NotificationSettingDialogNew extends StatelessWidget { subTitle: "用于定位当前位置推荐附的优惠动态", iconUrl: "https://alipic.lanhuapp.com/SketchPng409f144b2042e81840e20c2d528b3f50994869e3f22b5d7d2b8a47abcdb72953"); + static PermissModel photosPermissModel = PermissModel( + permissType: PermissType.photos, + title: "图库访问权限", + subTitle: "用于设置用户头像", + iconUrl: "https://alipic.lanhuapp.com/SketchPngb4dfa520067c3387340a16e558ba8138e6b1466e7e3ce019b70ae7bcbc6dfc63"); + static PermissModel cameraPermissModel = PermissModel( + permissType: PermissType.camera, + title: "摄像头访问权限", + subTitle: "用于拍照设置用户头像", + iconUrl: "https://alipic.lanhuapp.com/SketchPng404acd457590d35856e730a1d1c2a192a5ab570350130ea3d9b4fc84e51cc29d"); + static Future show(BuildContext context, {List permissModels}) async { List newPermissModels; if (permissModels == null) { @@ -307,6 +318,10 @@ class NotificationSettingDialogNew extends StatelessWidget { } } else if (item?.permissType == PermissType.location) { await Permission.location.request(); + }else if(item?.permissType==PermissType.camera){ + await Permission.camera.request(); + }else if(item?.permissType==PermissType.photos){ + await Permission.photos.request(); } } Navigator.pop(context, true); @@ -395,4 +410,4 @@ class PermissModel { PermissModel({this.iconUrl, this.title, this.subTitle, this.permissType}); } -enum PermissType { notification, storage, location } +enum PermissType { notification, storage, location,camera,photos} diff --git a/lib/pages/mine_detail_page/mine_detail_page.dart b/lib/pages/mine_detail_page/mine_detail_page.dart index 2ca74b7..23af856 100644 --- a/lib/pages/mine_detail_page/mine_detail_page.dart +++ b/lib/pages/mine_detail_page/mine_detail_page.dart @@ -8,6 +8,7 @@ import 'package:image_cropper/image_cropper.dart'; import 'package:image_picker/image_picker.dart'; import 'package:intl/intl.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart'; import 'package:zhiying_base_widget/dialog/loading/loading.dart'; import 'package:zhiying_base_widget/pages/mine_detail_page/mine_detail_bloc.dart'; import 'package:zhiying_base_widget/pages/mine_detail_page/models/mine_detail_model.dart'; @@ -50,19 +51,19 @@ class _MineDetailPageState extends State { backgroundColor: Colors.white, leading: Navigator.canPop(context) ? GestureDetector( - child: Container( - padding: EdgeInsets.zero, - child: Icon( - Icons.arrow_back_ios, - size: 20, - ), - ), - onTap: () { - if (Navigator.canPop(context)) { - Navigator.pop(context); - } - }, - ) + child: Container( + padding: EdgeInsets.zero, + child: Icon( + Icons.arrow_back_ios, + size: 20, + ), + ), + onTap: () { + if (Navigator.canPop(context)) { + Navigator.pop(context); + } + }, + ) : Container(), middle: Text( '个人信息', @@ -207,10 +208,10 @@ class _MineDetailContainerState extends State<_MineDetailContainer> { onTap == null ? Container() : Icon( - Icons.arrow_forward_ios, - size: 12, - color: Color(0xff999999), - ) + Icons.arrow_forward_ios, + size: 12, + color: Color(0xff999999), + ) ], ), ), @@ -256,10 +257,10 @@ class _MineDetailContainerState extends State<_MineDetailContainer> { onTap == null ? Container() : Icon( - Icons.arrow_forward_ios, - size: 12, - color: Color(0xff999999), - ) + Icons.arrow_forward_ios, + size: 12, + color: Color(0xff999999), + ) ], ), ), @@ -277,14 +278,14 @@ class _MineDetailContainerState extends State<_MineDetailContainer> { } void _selectImage() async { - var status = await Permission.photos.status; - if (status != PermissionStatus.granted) { - status = await Permission.photos.request(); - } - if (status == PermissionStatus.denied) { - Fluttertoast.showToast(msg: '暂无权限,图片选择失败'); - return null; - } + // var status = await Permission.photos.status; + // if (status != PermissionStatus.granted) { + // status = await Permission.photos.request(); + // } + // if (status == PermissionStatus.denied) { + // Fluttertoast.showToast(msg: '暂无权限,图片选择失败'); + // return null; + // } final picker = ImagePicker(); PickedFile file; @@ -300,66 +301,80 @@ class _MineDetailContainerState extends State<_MineDetailContainer> { backgroundColor: Colors.transparent); if (index != null) { if (index == 0) { - file = await picker.getImage(source: ImageSource.camera); + if (!await Permission.camera.isGranted) { + var result = await showDialog(context: context, child: NotificationSettingDialogNew([NotificationSettingDialogNew.cameraPermissModel])); + } + if (await Permission.camera.isGranted) { + file = await picker.getImage(source: ImageSource.camera); + } else { + Fluttertoast.showToast(msg: '暂无权限,图片拍取失败'); + } } else { - file = await picker.getImage(source: ImageSource.gallery); - } + if (!await Permission.storage.isGranted) { + var result = await showDialog(context: context, child: NotificationSettingDialogNew([NotificationSettingDialogNew.storagePermissModel])); + } + if (await Permission.storage.isGranted) { + file = await picker.getImage(source: ImageSource.gallery); + } else { + Fluttertoast.showToast(msg: '暂无权限,图片获取失败'); + } + } - if (file == null) return; - File cropperFile = await ImageCropper.cropImage( - sourcePath: file.path, - aspectRatioPresets: [ - CropAspectRatioPreset.square, - ], - androidUiSettings: AndroidUiSettings( - toolbarTitle: '图片剪裁', - toolbarColor: HexColor.fromHex('#E52425'), - toolbarWidgetColor: Colors.white, - initAspectRatio: CropAspectRatioPreset.original, - lockAspectRatio: true), - iosUiSettings: IOSUiSettings(minimumAspectRatio: 1.0, aspectRatioLockEnabled: true)); - if (cropperFile == null) { - return; - } - Loading.show(context); - File resultFile = await EncodeUtil.compressImage(context, file: cropperFile, size: 800); + if (file == null) return; + File cropperFile = await ImageCropper.cropImage( + sourcePath: file.path, + aspectRatioPresets: [ + CropAspectRatioPreset.square, + ], + androidUiSettings: AndroidUiSettings( + toolbarTitle: '图片剪裁', + toolbarColor: HexColor.fromHex('#E52425'), + toolbarWidgetColor: Colors.white, + initAspectRatio: CropAspectRatioPreset.original, + lockAspectRatio: true), + iosUiSettings: IOSUiSettings(minimumAspectRatio: 1.0, aspectRatioLockEnabled: true)); + if (cropperFile == null) { + return; + } + Loading.show(context); + File resultFile = await EncodeUtil.compressImage(context, file: cropperFile, size: 800); - _bloc.uploadAvatar(resultFile); + _bloc.uploadAvatar(resultFile); + } } - } - // 选择性别 - void _selectSex() async { - int index = await showModalBottomSheet( - context: context, - builder: (context) { - return ActionListAlert( - title: '选择性别', - actions: ['女', '男'], - ); - }, - isScrollControlled: false, - backgroundColor: Colors.transparent); - if (index != null) { - print(index); - _bloc.updateUser(gender: index == 0 ? '0' : '1'); + // 选择性别 + void _selectSex() async { + int index = await showModalBottomSheet( + context: context, + builder: (context) { + return ActionListAlert( + title: '选择性别', + actions: ['女', '男'], + ); + }, + isScrollControlled: false, + backgroundColor: Colors.transparent); + if (index != null) { + print(index); + _bloc.updateUser(gender: index == 0 ? '0' : '1'); + } } - } - void _selectBrithday() async { - DateTime dateTime = await showModalBottomSheet( - context: context, - builder: (context) { - return ActionDateAlert( - title: '选择出生日期', - maxTimeNew: "max", - ); - }, - isScrollControlled: false, - backgroundColor: Colors.transparent); - if (dateTime != null) { - String timeStamp = (dateTime.millisecondsSinceEpoch / 1000).ceil().toString(); - _bloc.updateUser(birthday: timeStamp); + void _selectBrithday() async { + DateTime dateTime = await showModalBottomSheet( + context: context, + builder: (context) { + return ActionDateAlert( + title: '选择出生日期', + maxTimeNew: "max", + ); + }, + isScrollControlled: false, + backgroundColor: Colors.transparent); + if (dateTime != null) { + String timeStamp = (dateTime.millisecondsSinceEpoch / 1000).ceil().toString(); + _bloc.updateUser(birthday: timeStamp); + } } } -} diff --git a/lib/pages/upload_wechat_page/upload_wechat_page.dart b/lib/pages/upload_wechat_page/upload_wechat_page.dart index 6f8ffb3..bf025aa 100644 --- a/lib/pages/upload_wechat_page/upload_wechat_page.dart +++ b/lib/pages/upload_wechat_page/upload_wechat_page.dart @@ -4,6 +4,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:image_picker/image_picker.dart'; import 'package:permission_handler/permission_handler.dart'; +import 'package:zhiying_base_widget/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart'; import 'package:zhiying_base_widget/pages/upload_wechat_page/bloc/upload_wechat_bloc.dart'; import 'package:zhiying_base_widget/pages/upload_wechat_page/bloc/upload_wechat_event.dart'; import 'package:zhiying_base_widget/pages/upload_wechat_page/bloc/upload_wechat_repository.dart'; @@ -48,9 +49,18 @@ class __UploadWeChatPageState extends State<_UploadWeChatPage> { Fluttertoast.showToast(msg: '暂无权限,图片选择失败'); return null; } - + PickedFile file; final picker = ImagePicker(); - PickedFile file = await picker.getImage(source: ImageSource.gallery); + + if (!await Permission.storage.isGranted) { + var result = await showDialog(context: context, child: NotificationSettingDialogNew([NotificationSettingDialogNew.storagePermissModel])); + } + if (await Permission.storage.isGranted) { + file = await picker.getImage(source: ImageSource.gallery); + } else { + Fluttertoast.showToast(msg: '暂无权限,图片获取失败'); + } + if (file == null) return;