mirror of
https://github.com/foss42/apidash.git
synced 2025-05-29 21:06:01 +08:00
Add saveToDownloads
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:apidash/utils/utils.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
||||
@ -20,3 +21,30 @@ Future<void> saveCollection(
|
||||
sm.hideCurrentSnackBar();
|
||||
sm.showSnackBar(getSnackBar(message, small: false));
|
||||
}
|
||||
|
||||
Future<void> saveToDownloads(
|
||||
ScaffoldMessengerState sm, {
|
||||
Uint8List? content,
|
||||
String? mimeType,
|
||||
String? ext,
|
||||
String? name,
|
||||
}) async {
|
||||
var message = "";
|
||||
var path = await getFileDownloadpath(
|
||||
name,
|
||||
ext ?? getFileExtension(mimeType),
|
||||
);
|
||||
if (path != null) {
|
||||
try {
|
||||
await saveFile(path, content!);
|
||||
var sp = getShortPath(path);
|
||||
message = 'Saved to $sp';
|
||||
} catch (e) {
|
||||
message = "An error occurred while saving file.";
|
||||
}
|
||||
} else {
|
||||
message = "Unable to determine the download path.";
|
||||
}
|
||||
sm.hideCurrentSnackBar();
|
||||
sm.showSnackBar(getSnackBar(message, small: false));
|
||||
}
|
||||
|
Reference in New Issue
Block a user