49 lines
1.5 KiB
Dart
49 lines
1.5 KiB
Dart
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,
|
|
);
|
|
}
|
|
}
|
|
}
|