-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bfe996f
commit 69da27e
Showing
5 changed files
with
92 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:device_info_plus/device_info_plus.dart'; | ||
import 'package:dio/dio.dart'; | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:image_gallery_saver/image_gallery_saver.dart'; | ||
import 'package:miria/providers.dart'; | ||
import 'package:misskey_dart/misskey_dart.dart' hide Permission; | ||
import 'package:permission_handler/permission_handler.dart'; | ||
|
||
class DownloadFileNotifier extends Notifier<void> { | ||
@override | ||
void build() { | ||
return; | ||
} | ||
|
||
Future<void> downloadFile(DriveFile driveFile) async { | ||
if (defaultTargetPlatform == TargetPlatform.android) { | ||
final androidInfo = await DeviceInfoPlugin().androidInfo; | ||
if (androidInfo.version.sdkInt <= 32) { | ||
final permissionStatus = await Permission.storage.status; | ||
if (permissionStatus.isDenied) { | ||
await Permission.storage.request(); | ||
} | ||
} else { | ||
final permissionStatus = await Permission.photos.status; | ||
if (permissionStatus.isDenied) { | ||
await Permission.photos.request(); | ||
} | ||
} | ||
} | ||
|
||
final tempDir = ref.read(fileSystemProvider).systemTempDirectory; | ||
final savePath = "${tempDir.path}/${driveFile.name}"; | ||
|
||
await ref.read(dioProvider).download( | ||
driveFile.url, | ||
savePath, | ||
options: Options( | ||
responseType: ResponseType.bytes, | ||
), | ||
); | ||
|
||
await ImageGallerySaver.saveFile( | ||
savePath, | ||
name: driveFile.name, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters