getFileName static method
get file name from file path or url
Implementation
static String getFileName(String? path, {bool withExtension = true}) {
String fileName = "";
if (withExtension) {
if (!Files._isNullOREmpty(path)) {
if (path.toString().contains("/")) {
fileName =
(path.toString().substring(path.toString().lastIndexOf("/")))
.replaceAll("/", "");
} else {
fileName = path.toString();
}
}
} else {
if (!Files._isNullOREmpty(path)) {
if (path.toString().contains("/")) {
fileName =
((path.toString().substring(path.toString().lastIndexOf("/")))
.replaceAll("/", ""))
.replaceAll(Files.getFileExtension(path), "");
} else {
fileName =
(path.toString()).replaceAll(Files.getFileExtension(path), "");
}
}
}
return fileName;
}