Skip to content

Commit

Permalink
🚚 Remove web implementation of save_file
Browse files Browse the repository at this point in the history
  • Loading branch information
iqfareez committed Mar 4, 2024
1 parent a0ebf11 commit f15392a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 102 deletions.
49 changes: 41 additions & 8 deletions lib/features/schedule_viewer/saved/utils/save_file.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,49 @@
import 'dart:io';
import 'dart:typed_data';

import '../../../../platform_impl/not_web_save_file.dart'
if (dart.library.io) '../../../../platform_impl/not_web_save_file.dart'
if (dart.library.html) '../../../../platform_impl/web_save_file.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

class SaveFile {
final SaveImpl _saveImpl;

SaveFile() : _saveImpl = SaveImpl();

Future<String?> save(
Uint8List pngBytes, String filename, bool tempPath) async {
return _saveImpl.save(pngBytes, filename, tempPath);
String? saveDirectory;
if (tempPath) {
if (Platform.isWindows) {
saveDirectory = await getApplicationDocumentsDirectory()
.then((value) => value.path);
} else {
// Android
saveDirectory =
await getTemporaryDirectory().then((value) => value.path);
}
} else {
if (Platform.isAndroid) {
var status = await Permission.storage.request();
if (status.isDenied) throw Exception('Permission denied');

// create/use Picture folder

final folderDirectory =
await Directory('/storage/emulated/0/Pictures/IIUM Schedule')
.create();
saveDirectory = folderDirectory.path;
}

if (Platform.isWindows) {
final downloadDirectory = await getDownloadsDirectory();
// use download folder
final folderDirectory =
await Directory('${downloadDirectory!.path}/IIUM Schedule')
.create();

saveDirectory = folderDirectory.path;
}
}

File imgFile = File('$saveDirectory/$filename.png');
imgFile.writeAsBytes(pngBytes);

return imgFile.path;
}
}
5 changes: 0 additions & 5 deletions lib/platform_impl/base_save_file.dart

This file was deleted.

54 changes: 0 additions & 54 deletions lib/platform_impl/not_web_save_file.dart

This file was deleted.

10 changes: 0 additions & 10 deletions lib/platform_impl/stub_save_file.dart

This file was deleted.

25 changes: 0 additions & 25 deletions lib/platform_impl/web_save_file.dart

This file was deleted.

0 comments on commit f15392a

Please sign in to comment.