From e3f4344ae9c1ec93860d4c5d1b8de1a803b29569 Mon Sep 17 00:00:00 2001 From: Kingkor Roy Tirtho Date: Tue, 8 Aug 2023 10:39:15 +0600 Subject: [PATCH] fix(android): android 13 local tracks not showing up --- android/app/src/main/AndroidManifest.xml | 1 + lib/components/library/user_local_tracks.dart | 19 +++++++++++++++++-- pubspec.lock | 6 +++--- pubspec.yaml | 1 + 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index f47bab2ef..fb6edbd6f 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ + diff --git a/lib/components/library/user_local_tracks.dart b/lib/components/library/user_local_tracks.dart index 86880820f..a36be2830 100644 --- a/lib/components/library/user_local_tracks.dart +++ b/lib/components/library/user_local_tracks.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:catcher/catcher.dart'; +import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; @@ -169,11 +170,25 @@ class UserLocalTracks extends HookConsumerWidget { useAsyncEffect( () async { if (!kIsMobile) return; - if (!await Permission.storage.isGranted && - !await Permission.storage.isLimited) { + + final androidInfo = await DeviceInfoPlugin().androidInfo; + + final hasNoStoragePerm = androidInfo.version.sdkInt < 33 && + !await Permission.storage.isGranted && + !await Permission.storage.isLimited; + + final hasNoAudioPerm = androidInfo.version.sdkInt >= 33 && + !await Permission.audio.isGranted && + !await Permission.audio.isLimited; + + if (hasNoStoragePerm) { await Permission.storage.request(); if (isMounted()) ref.refresh(localTracksProvider); } + if (hasNoAudioPerm) { + await Permission.audio.request(); + if (isMounted()) ref.refresh(localTracksProvider); + } }, null, [], diff --git a/pubspec.lock b/pubspec.lock index 778e23f63..a41249e84 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -419,13 +419,13 @@ packages: source: hosted version: "1.1.0" device_info_plus: - dependency: transitive + dependency: "direct main" description: name: device_info_plus - sha256: "9b1a0c32b2a503f8fe9f8764fac7b5fcd4f6bd35d8f49de5350bccf9e2a33b8a" + sha256: "86add5ef97215562d2e090535b0a16f197902b10c369c558a100e74ea06e8659" url: "https://pub.dev" source: hosted - version: "9.0.0" + version: "9.0.3" device_info_plus_platform_interface: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 9a77cb32e..85aba0cf3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -102,6 +102,7 @@ dependencies: google_fonts: ^4.0.4 supabase: ^1.9.9 dio: ^5.3.2 + device_info_plus: ^9.0.3 dev_dependencies: build_runner: ^2.3.2