Skip to content

Commit

Permalink
permissions and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
user5522 committed Jan 3, 2025
1 parent b13b90e commit b58b87c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
7 changes: 5 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<!-- deprecated in Android 13-->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:label="Timetable"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:fullBackupOnly="false"
>
<activity
android:name=".MainActivity"
Expand Down
4 changes: 4 additions & 0 deletions lib/db/services/service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:share_plus/share_plus.dart';
import 'package:timetable/constants/days.dart';
import 'package:timetable/constants/rotation_weeks.dart';
import 'package:timetable/db/database.dart';
import 'package:timetable/helpers/request_permission.dart';

Future<void> shareFile(File file) async {
Share.shareXFiles([XFile(file.path)]);
Expand All @@ -29,6 +30,9 @@ Future<void> exportData(AppDatabase db) async {
final String fileName = 'timetable_backup_$date.json';

try {
final isGranted = await requestStoragePermission();
if (!isGranted) return;

final Map<String, List<dynamic>> allData = {
'subject': await db.subject.select().get(),
'timetable': await db.timetable.select().get(),
Expand Down
19 changes: 19 additions & 0 deletions lib/helpers/request_permission.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import 'package:permission_handler/permission_handler.dart';
import 'package:timetable/helpers/get_os_version.dart';

Future<bool> requestStoragePermission() async {
final int androidVersion = await getAndroidVersion();
bool status;

if (androidVersion >= 33) {
final photos = await Permission.photos.request();
final videos = await Permission.videos.request();

status = photos.isGranted && videos.isGranted;
} else {
final storage = await Permission.storage.request();
status = storage.isGranted;
}

return status;
}
48 changes: 48 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,54 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
sha256: "18bf33f7fefbd812f37e72091a15575e72d5318854877e0e4035a24ac1113ecb"
url: "https://pub.dev"
source: hosted
version: "11.3.1"
permission_handler_android:
dependency: transitive
description:
name: permission_handler_android
sha256: "71bbecfee799e65aff7c744761a57e817e73b738fedf62ab7afd5593da21f9f1"
url: "https://pub.dev"
source: hosted
version: "12.0.13"
permission_handler_apple:
dependency: transitive
description:
name: permission_handler_apple
sha256: e6f6d73b12438ef13e648c4ae56bd106ec60d17e90a59c4545db6781229082a0
url: "https://pub.dev"
source: hosted
version: "9.4.5"
permission_handler_html:
dependency: transitive
description:
name: permission_handler_html
sha256: "38f000e83355abb3392140f6bc3030660cfaef189e1f87824facb76300b4ff24"
url: "https://pub.dev"
source: hosted
version: "0.1.3+5"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
sha256: e9c8eadee926c4532d0305dff94b85bf961f16759c3af791486613152af4b4f9
url: "https://pub.dev"
source: hosted
version: "4.2.3"
permission_handler_windows:
dependency: transitive
description:
name: permission_handler_windows
sha256: "1a790728016f79a41216d88672dbc5df30e686e811ad4e698bfc51f76ad91f1e"
url: "https://pub.dev"
source: hosted
version: "0.2.1"
platform:
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 @@ -47,6 +47,7 @@ dependencies:
sqlite3: ^2.4.0
easy_localization: ^3.0.5
share_plus: ^10.1.3
permission_handler: ^11.3.1

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit b58b87c

Please sign in to comment.