setup static method
dynamic
setup()
初始化路径的环境
该方法用于设置应用程序的文件路径,包括数据库路径、图像路径、库路径和临时路径。
如果环境变量 FLUTTER_TEST 设置为 true,则使用 FLUTTER_TEST_HOME 环境变量作为库路径。
否则,根据平台类型(iOS、macOS、Android)获取相应的目录路径。
Implementation
static setup() async {
if (loaded) return;
if (Platform.environment['FLUTTER_TEST'] == "true") {
String? home = Platform.environment['FLUTTER_TEST_HOME'];
_library = home!;
} else {
if (Platform.isIOS || Platform.isMacOS) {
var dir = await getLibraryDirectory();
_library = dir.path;
} else if (Platform.isAndroid) {
var dir = await getApplicationDocumentsDirectory();
_library = dir.path;
}
}
_db = _library + '/storage.db';
_image = _library + '/image/';
_temp = _library + '/${Uuid().v4()}/';
Directory imageDir = Directory(_image);
await imageDir.create(recursive: true);
loaded = true;
}