Skip to content

Commit

Permalink
fix(android): android 13 local tracks not showing up
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Aug 8, 2023
1 parent e7c6813 commit e3f4344
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
1 change: 1 addition & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>

<queries>
<!-- If your app opens https URLs -->
Expand Down
19 changes: 17 additions & 2 deletions lib/components/library/user_local_tracks.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
[],
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3f4344

Please sign in to comment.