mirror of
https://github.com/foss42/apidash.git
synced 2025-06-29 20:37:12 +08:00
Add saveToDownloads
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:apidash/utils/utils.dart';
|
import 'package:apidash/utils/utils.dart';
|
||||||
import 'package:apidash/widgets/widgets.dart';
|
import 'package:apidash/widgets/widgets.dart';
|
||||||
|
|
||||||
@ -20,3 +21,30 @@ Future<void> saveCollection(
|
|||||||
sm.hideCurrentSnackBar();
|
sm.hideCurrentSnackBar();
|
||||||
sm.showSnackBar(getSnackBar(message, small: false));
|
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));
|
||||||
|
}
|
||||||
|
@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:apidash/utils/utils.dart';
|
import 'package:apidash/utils/utils.dart';
|
||||||
import 'package:apidash/consts.dart';
|
import 'package:apidash/consts.dart';
|
||||||
import "snackbars.dart";
|
|
||||||
|
|
||||||
class SaveInDownloadsButton extends StatelessWidget {
|
class SaveInDownloadsButton extends StatelessWidget {
|
||||||
const SaveInDownloadsButton({
|
const SaveInDownloadsButton({
|
||||||
@ -29,26 +28,13 @@ class SaveInDownloadsButton extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
const label = kLabelDownload;
|
const label = kLabelDownload;
|
||||||
final onPressed = (content != null)
|
final onPressed = (content != null)
|
||||||
? () async {
|
? () => saveToDownloads(
|
||||||
var message = "";
|
sm,
|
||||||
var path = await getFileDownloadpath(
|
content: content,
|
||||||
name,
|
mimeType: mimeType,
|
||||||
ext ?? getFileExtension(mimeType),
|
ext: ext,
|
||||||
);
|
name: name,
|
||||||
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));
|
|
||||||
}
|
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
return showLabel
|
return showLabel
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
import 'package:apidash/main.dart';
|
import 'package:apidash/main.dart';
|
||||||
import 'package:apidash/app.dart';
|
import 'package:apidash/app.dart';
|
||||||
import 'package:apidash/common/utils.dart';
|
|
||||||
import 'package:apidash/screens/screens.dart';
|
import 'package:apidash/screens/screens.dart';
|
||||||
|
|
||||||
void main() {}
|
void main() {}
|
||||||
|
Reference in New Issue
Block a user