From a8f7405938a931a0bc6f1f963a41093dcab145e8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 15 Jul 2023 16:44:35 +0300 Subject: [PATCH] version 0.4.9 --- .flutter-plugins | 21 ++--- .flutter-plugins-dependencies | 2 +- CHANGELOG.md | 5 ++ README.md | 7 ++ .../android/app/src/main/AndroidManifest.xml | 2 + example/pubspec.lock | 80 +++++++++++++++---- lib/controller/gallery_controller.dart | 75 ++++++++++++----- .../gallery_picker_view.dart | 3 +- pubspec.yaml | 9 ++- 9 files changed, 150 insertions(+), 54 deletions(-) diff --git a/.flutter-plugins b/.flutter-plugins index fb559bc..559dd8a 100644 --- a/.flutter-plugins +++ b/.flutter-plugins @@ -1,11 +1,12 @@ # This is a generated file; do not edit or check into version control. -permission_handler=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler-10.2.0\\ -permission_handler_android=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_android-10.2.0\\ -permission_handler_apple=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_apple-9.0.8\\ -permission_handler_windows=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_windows-0.1.2\\ -photo_gallery=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\photo_gallery-1.2.2\\ -video_player=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player-2.6.1\\ -video_player_android=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player_android-2.4.4\\ -video_player_avfoundation=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player_avfoundation-2.4.3\\ -video_player_web=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player_web-2.0.16\\ -video_thumbnail=C:\\Users\\MrWorldWide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_thumbnail-0.5.3\\ +device_info_plus=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\device_info_plus-9.0.2\\ +permission_handler=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler-10.4.3\\ +permission_handler_android=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_android-10.3.2\\ +permission_handler_apple=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_apple-9.1.4\\ +permission_handler_windows=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\permission_handler_windows-0.1.3\\ +photo_gallery=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\photo_gallery-1.2.2\\ +video_player=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player-2.7.0\\ +video_player_android=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player_android-2.4.4\\ +video_player_avfoundation=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player_avfoundation-2.4.3\\ +video_player_web=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_player_web-2.0.16\\ +video_thumbnail=C:\\Users\\MrWorldwide\\AppData\\Local\\Pub\\Cache\\hosted\\pub.dev\\video_thumbnail-0.5.3\\ diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index a8cce5d..b4ecf0d 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"permission_handler_apple","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_apple-9.0.8\\\\","native_build":true,"dependencies":[]},{"name":"photo_gallery","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\photo_gallery-1.2.2\\\\","native_build":true,"dependencies":[]},{"name":"video_player_avfoundation","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_player_avfoundation-2.4.3\\\\","native_build":true,"dependencies":[]},{"name":"video_thumbnail","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_thumbnail-0.5.3\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"permission_handler_android","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_android-10.2.0\\\\","native_build":true,"dependencies":[]},{"name":"photo_gallery","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\photo_gallery-1.2.2\\\\","native_build":true,"dependencies":[]},{"name":"video_player_android","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_player_android-2.4.4\\\\","native_build":true,"dependencies":[]},{"name":"video_thumbnail","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_thumbnail-0.5.3\\\\","native_build":true,"dependencies":[]}],"macos":[],"linux":[],"windows":[{"name":"permission_handler_windows","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_windows-0.1.2\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"video_player_web","path":"C:\\\\Users\\\\MrWorldWide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_player_web-2.0.16\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]},{"name":"photo_gallery","dependencies":[]},{"name":"video_player","dependencies":["video_player_android","video_player_avfoundation","video_player_web"]},{"name":"video_player_android","dependencies":[]},{"name":"video_player_avfoundation","dependencies":[]},{"name":"video_player_web","dependencies":[]},{"name":"video_thumbnail","dependencies":[]}],"date_created":"2023-05-16 15:46:42.053591","version":"3.10.0"} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"device_info_plus","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.0.2\\\\","native_build":true,"dependencies":[]},{"name":"permission_handler_apple","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_apple-9.1.4\\\\","native_build":true,"dependencies":[]},{"name":"photo_gallery","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\photo_gallery-1.2.2\\\\","native_build":true,"dependencies":[]},{"name":"video_player_avfoundation","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_player_avfoundation-2.4.3\\\\","native_build":true,"dependencies":[]},{"name":"video_thumbnail","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_thumbnail-0.5.3\\\\","native_build":true,"dependencies":[]}],"android":[{"name":"device_info_plus","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.0.2\\\\","native_build":true,"dependencies":[]},{"name":"permission_handler_android","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_android-10.3.2\\\\","native_build":true,"dependencies":[]},{"name":"photo_gallery","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\photo_gallery-1.2.2\\\\","native_build":true,"dependencies":[]},{"name":"video_player_android","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_player_android-2.4.4\\\\","native_build":true,"dependencies":[]},{"name":"video_thumbnail","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_thumbnail-0.5.3\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"device_info_plus","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.0.2\\\\","native_build":true,"dependencies":[]}],"linux":[{"name":"device_info_plus","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.0.2\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"device_info_plus","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.0.2\\\\","native_build":false,"dependencies":[]},{"name":"permission_handler_windows","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\permission_handler_windows-0.1.3\\\\","native_build":true,"dependencies":[]}],"web":[{"name":"device_info_plus","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\device_info_plus-9.0.2\\\\","dependencies":[]},{"name":"video_player_web","path":"C:\\\\Users\\\\MrWorldwide\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\video_player_web-2.0.16\\\\","dependencies":[]}]},"dependencyGraph":[{"name":"device_info_plus","dependencies":[]},{"name":"permission_handler","dependencies":["permission_handler_android","permission_handler_apple","permission_handler_windows"]},{"name":"permission_handler_android","dependencies":[]},{"name":"permission_handler_apple","dependencies":[]},{"name":"permission_handler_windows","dependencies":[]},{"name":"photo_gallery","dependencies":[]},{"name":"video_player","dependencies":["video_player_android","video_player_avfoundation","video_player_web"]},{"name":"video_player_android","dependencies":[]},{"name":"video_player_avfoundation","dependencies":[]},{"name":"video_player_web","dependencies":[]},{"name":"video_thumbnail","dependencies":[]}],"date_created":"2023-07-15 16:44:05.568875","version":"3.10.5"} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ef199b0..ac9e84b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -172,4 +172,9 @@ ## 0.4.8 * Dart 3 & Flutter 3.10 compatibility + +## 0.4.9 + +* Fixed permission issue for android sdk 33 and above. +* https://github.com/FlutterWay/gallery_picker/issues/1 is fixed \ No newline at end of file diff --git a/README.md b/README.md index 0882ad6..f7dd1c1 100644 --- a/README.md +++ b/README.md @@ -64,9 +64,16 @@ You could find the code samples of the given gifs below in `/example/lib/example #### Android Add uses-permission `android/app/src/main/AndroidManifest.xml` file + ```xml ``` + for android sdk 33 and above + ```xml + + + ``` + #### Ios Add these configurations to your `ios/Runner/info.plist` file ```xml diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index cde9521..2a7748e 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -2,6 +2,8 @@ package="com.example.gallery_picker_example"> + + =3.0.0-0 <4.0.0" + dart: ">=3.0.0 <4.0.0" flutter: ">=3.3.0" diff --git a/lib/controller/gallery_controller.dart b/lib/controller/gallery_controller.dart index dcb3e6d..6588591 100644 --- a/lib/controller/gallery_controller.dart +++ b/lib/controller/gallery_controller.dart @@ -1,15 +1,18 @@ import 'dart:async'; import 'dart:io'; + +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:photo_gallery/photo_gallery.dart'; -import '../models/config.dart'; -import '../models/gallery_media.dart'; + import '/models/gallery_album.dart'; import '/models/medium.dart'; +import '../models/config.dart'; +import '../models/gallery_media.dart'; import '../models/media_file.dart'; import 'picker_listener.dart'; @@ -168,28 +171,39 @@ class PhoneGalleryController extends GetxController { } static Future promptPermissionSetting() async { - await PhoneGalleryController.requestStatus(Permission.storage); - if (Platform.isIOS) { - await PhoneGalleryController.requestStatus(Permission.photos); + if (Platform.isAndroid) { + final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin(); + final AndroidDeviceInfo info = await deviceInfoPlugin.androidInfo; + if (info.version.sdkInt >= 33) { + if (await PhoneGalleryController.requestPermission(Permission.photos)) { + return await PhoneGalleryController.requestPermission( + Permission.videos); + } else { + return false; + } + } else { + return await PhoneGalleryController.requestPermission( + Permission.storage); + } } - if (Platform.isIOS && - await Permission.storage.isGranted && - await Permission.photos.isGranted || - Platform.isAndroid && await Permission.storage.isGranted) { - return true; + bool statusStorage = + await PhoneGalleryController.requestPermission(Permission.storage); + if (statusStorage) { + return await PhoneGalleryController.requestPermission(Permission.photos); } return false; } - static Future requestStatus(Permission permission) async { - while (true) { - try { - await permission.request(); - break; - } catch (e) { - await Future.delayed(const Duration(milliseconds: 500), () {}); + static Future requestPermission(Permission permission) async { + if (await permission.isGranted) { + return true; + } else { + var result = await permission.request(); + if (result == PermissionStatus.granted) { + return true; } } + return false; } Future initializeAlbums() async { @@ -213,13 +227,31 @@ class PhoneGalleryController extends GetxController { void permissionListener() { Timer.periodic(const Duration(seconds: 1), (timer) async { - if (await Permission.storage.isGranted) { + if (await isGranted()) { initializeAlbums(); timer.cancel(); } }); } + Future isGranted() async { + if (Platform.isAndroid) { + final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin(); + final AndroidDeviceInfo info = await deviceInfoPlugin.androidInfo; + if (info.version.sdkInt >= 33) { + if (await Permission.photos.isGranted) { + return await Permission.videos.isGranted; + } else { + return false; + } + } else { + return await Permission.storage.isGranted; + } + } + return (await Permission.storage.isGranted) && + (await Permission.photos.isGranted); + } + static Future get collectGallery async { if (await promptPermissionSetting()) { List tempGalleryAlbums = []; @@ -228,14 +260,13 @@ class PhoneGalleryController extends GetxController { await PhotoGallery.listAlbums(mediumType: MediumType.image); List videoAlbums = await PhotoGallery.listAlbums(mediumType: MediumType.video); - for (var photoAlbum in photoAlbums) { GalleryAlbum entireGalleryAlbum = GalleryAlbum.album(photoAlbum); await entireGalleryAlbum.initialize(); entireGalleryAlbum.setType = AlbumType.image; - if (videoAlbums.any((element) => element.name == photoAlbum.name)) { - Album videoAlbum = videoAlbums - .singleWhere((element) => element.name == photoAlbum.name); + if (videoAlbums.any((element) => element.id == photoAlbum.id)) { + Album videoAlbum = + videoAlbums.singleWhere((element) => element.id == photoAlbum.id); GalleryAlbum videoGalleryAlbum = GalleryAlbum.album(videoAlbum); await videoGalleryAlbum.initialize(); DateTime? lastPhotoDate = entireGalleryAlbum.lastDate; diff --git a/lib/views/gallery_picker_view/gallery_picker_view.dart b/lib/views/gallery_picker_view/gallery_picker_view.dart index bec8185..be2899f 100644 --- a/lib/views/gallery_picker_view/gallery_picker_view.dart +++ b/lib/views/gallery_picker_view/gallery_picker_view.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; + import '../../controller/gallery_controller.dart'; import '../../models/config.dart'; import '../../models/gallery_album.dart'; import '../../models/media_file.dart'; import '../album_categories_view/album_categories_view.dart'; -import '../album_view/album_page.dart'; import '../album_view/album_medias_view.dart'; +import '../album_view/album_page.dart'; import 'permission_denied_view.dart'; import 'picker_appbar.dart'; import 'reload_gallery.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index f39968e..bd44349 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: gallery_picker description: Gallery Picker is a flutter package that will allow you to pick media file(s), manage and navigate inside your gallery with modern tools and views. -version: 0.4.8 +version: 0.4.9 homepage: https://github.com/FlutterWay/gallery_picker environment: @@ -12,12 +12,13 @@ dependencies: sdk: flutter cupertino_icons: ^1.0.5 photo_gallery: ^1.2.2 - permission_handler: ^10.2.0 + permission_handler: ^10.4.3 transparent_image: ^2.0.1 - video_player: ^2.6.1 + video_player: ^2.7.0 + device_info_plus: ^9.0.2 get: ^4.6.5 video_thumbnail: ^0.5.3 - intl: ^0.17.0 + intl: ^0.18.1 page_transition: ^2.0.9 bottom_sheet_scaffold: ^0.1.6 dev_dependencies: