Untitled
unknown
dart
2 years ago
3.7 kB
1
Indexable
Never
import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:iketfaa_delivery/App/Common/Services/AuthenticationService/Core/manager.dart'; import 'package:iketfaa_delivery/App/Common/Services/PermissionService/permission_handler_service.dart'; import 'package:image_picker/image_picker.dart'; import 'package:multi_image_picker2/multi_image_picker2.dart'; import 'package:path_provider/path_provider.dart'; class PickImageCamera extends StatelessWidget { final AuthenticationManager authManager = Get.find(); final Function returnImage; final String fileNameTitle; PickImageCamera({required this.fileNameTitle, required this.returnImage}); @override Widget build(BuildContext context) { return CupertinoAlertDialog( title: Container( margin: const EdgeInsets.only(bottom: 10.0), child: Text( fileNameTitle, style: Get.textTheme.headline3, ), ), content: Text( 'Choose photo'.tr, style: Get.textTheme.headline5, ), actions: [ CupertinoDialogAction( isDefaultAction: true, child: Text( 'photos'.tr, style: Get.textTheme.headline6! .copyWith(color: CupertinoColors.activeBlue), ), onPressed: () async { Navigator.pop(context); bool per = await PermissionHandlerPermissionService() .handlePhotosPermission(context); if (per) { await MultiImagePicker.pickImages( maxImages: 1, enableCamera: true, selectedAssets: [], cupertinoOptions: const CupertinoOptions( takePhotoIcon: 'chat', ), materialOptions: const MaterialOptions( actionBarColor: '#339A58', statusBarColor: '#339A58', allViewTitle: 'All Photos', useDetailsView: false, selectCircleStrokeColor: '#339A58', ), ).then((value) async { var bytes = await value[0].getByteData(quality: 20); String dir = (await getApplicationDocumentsDirectory()).path; await authManager.commonTools .writeToFile(bytes, '$dir/${value[0].name}.jpg'); File tempFile = File(''); tempFile = File('$dir/${value[0].name}.jpg'); returnImage(tempFile); }); } }, ), CupertinoDialogAction( isDefaultAction: true, child: Text( 'camera'.tr, style: Get.textTheme.headline6! .copyWith(color: CupertinoColors.activeBlue), ), onPressed: () async { Navigator.pop(context); bool per = await PermissionHandlerPermissionService() .handleCameraPermission(context); if (per) { final ImagePicker _picker = ImagePicker(); final XFile? tempFile = await _picker.pickImage( source: ImageSource.camera, imageQuality: 20); if (tempFile != null) returnImage(File(tempFile.path)); else return returnImage(File('')); } }, ), CupertinoDialogAction( isDefaultAction: true, child: Text('cancel'.tr, style: Get.textTheme.headline6! .copyWith(color: CupertinoColors.activeBlue)), onPressed: () async { Navigator.of(context).pop(); }, ) ], ); } }