ANDREAS_LATANOWSKY_CPD_1910877/lib/file_utils.dart

49 lines
1.5 KiB
Dart
Raw Permalink Normal View History

2024-01-10 23:39:33 +01:00
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'dart:typed_data';
class FileUtils {
static void saveTranslatedImage(Uint8List translatedImage) async {
if (Platform.isAndroid) {
final result = await ImageGallerySaver.saveImage(translatedImage);
if (result['isSuccess']) {
Fluttertoast.showToast(
msg: "Image saved successfully!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0,
);
} else {
Fluttertoast.showToast(
msg: "Failed to save image",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.red,
textColor: Colors.white,
fontSize: 16.0,
);
}
} else {
//vorerst... finde noch was besseres
final file = File('C:/Users/hfggvcb/Desktop/image.png');
await file.writeAsBytes(translatedImage);
Fluttertoast.showToast(
msg: "Image saved successfully on Windows!",
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
backgroundColor: Colors.green,
textColor: Colors.white,
fontSize: 16.0,
);
}
}
}