feat: extension support (#78)

This commit is contained in:
Levi authored and GitHub committed 2023-10-16 09:47:31 +08:00
1 parent 82d316af83
commit c073fc0a67
118 files changed
+6971 -780

No files matched your search

+34 -1
View File
@@ -3,8 +3,23 @@ import 'dart:convert';
import 'dart:io';
import 'package:flutter/foundation.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as path;
class Util {
static String? _storageDir;
static String cleanPath(String path) {
path = path.replaceAll(RegExp(r'\\'), "/");
if (path.startsWith(".")) {
path = path.substring(1);
}
if (path.startsWith("/")) {
path = path.substring(1);
}
return path;
}
static String safeDir(String path) {
if (path == "." || path == "./" || path == ".\\") {
return "";
@@ -33,6 +48,24 @@ class Util {
}
}
static Future<void> initStorageDir() async {
var storageDir = "./";
if (Platform.isAndroid) {
storageDir = (await getExternalStorageDirectory())?.path ?? storageDir;
} else if (Platform.isIOS) {
storageDir = (await getLibraryDirectory()).path;
}
_storageDir = storageDir;
}
static String getStorageDir() {
return _storageDir!;
}
static String getStorageAsset(String asset) {
return path.join(getStorageDir(), asset);
}
static isAndroid() {
return !kIsWeb && Platform.isAndroid;
}
@@ -76,7 +109,7 @@ class Util {
return [];
}
const ls = LineSplitter();
return ls.convert(text);
return ls.convert(text).where((line) => line.isNotEmpty).toList();
}
// if one future complete, return the result, only all future error, return the last error