saveFromFile method
Future method saveFromFile takes the File file from dart:io return String value the path of savedFile Or It Can return String ERROR From catch()
Implementation
@override
Future<String> saveFromFile({required File file}) async {
try {
if (file.existsSync()) {
final fData = file.readAsBytesSync();
if (fData.isNotEmpty) {
final fName = _baseName(file.path);
final fType = _baseType(file.path);
final val = await _saveFile(fileName: fName);
if (val.isNotEmpty) {
if (val.endsWith(fType)) {
final fF = File(val);
fF.writeAsBytesSync(fData);
return fF.path;
} else {
final fF = File(val);
fF.writeAsBytesSync(fData);
var newPath = val.substring(
0, val.lastIndexOf(Platform.pathSeparator) + 1) +
_baseName(val) +
fType;
fF.renameSync(newPath);
return newPath;
}
} else {
return "Couldn't Write File Data";
}
} else {
return "Couldn't Read File Data";
}
} else {
return "NotExist";
}
} catch (e) {
return e.toString();
}
}