Parcourir la source

1.更新权限获取弹窗显示

tags/0.0.15+5
“yanghuaxuan” il y a 3 ans
Parent
révision
113bcd15ef
3 fichiers modifiés avec 126 ajouts et 86 suppressions
  1. +16
    -1
      lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart
  2. +98
    -83
      lib/pages/mine_detail_page/mine_detail_page.dart
  3. +12
    -2
      lib/pages/upload_wechat_page/upload_wechat_page.dart

+ 16
- 1
lib/dialog/global_dialog/notification_setting_dialog/notification_setting_dialog.dart Voir le fichier

@@ -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<PermissModel> permissModels}) async {
List<PermissModel> 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}

+ 98
- 83
lib/pages/mine_detail_page/mine_detail_page.dart Voir le fichier

@@ -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<MineDetailPage> {
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);
}
}
}
}

+ 12
- 2
lib/pages/upload_wechat_page/upload_wechat_page.dart Voir le fichier

@@ -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;



Chargement…
Annuler
Enregistrer