Flutter 在Flatter应用程序中找到资产文件的路径
我使用的软件包(Starflut)需要使用存储在资产中的文件 我首先将此文件添加到pubspec.yaml中:Flutter 在Flatter应用程序中找到资产文件的路径,flutter,dart,flutter-dependencies,Flutter,Dart,Flutter Dependencies,我使用的软件包(Starflut)需要使用存储在资产中的文件 我首先将此文件添加到pubspec.yaml中: assets: - my_folder/my_file.py 然后,我在运行应用程序时尝试查找此文件,但它不在以下目录或其任何子文件夹中: /data/user/0/com.example.my_应用程序 /data/data/com.example.my_应用程序 如何定位assets/my_file.py以便从包(starflut)中使用它 谢谢因为您的资产中包含
assets:
- my_folder/my_file.py
然后,我在运行应用程序时尝试查找此文件,但它不在以下目录或其任何子文件夹中:
- /data/user/0/com.example.my_应用程序
- /data/data/com.example.my_应用程序
谢谢因为您的资产中包含了应用程序,所以您必须将文件从rootBundle复制到temp目录或所需位置。您可以查看有关如何读取资产文件和写入应用程序路径的信息 希望这有帮助
import 'package:path_provider/path_provider.dart';
import 'dart:io';
...
var aux=Directory("/data/user/0/com.example.my_app");
//var aux=Directory("/data/data/com.example.my_app/files");
var files = aux.listSync(recursive:true).toList();
print(files[2]);
for(var i=0; i<files.length; i++){
print(files[i]);
}
Directory tempDir = await getTemporaryDirectory(); // /data/user/0/com.example.my_app/cache
Directory appDocDir = await getApplicationDocumentsDirectory(); // /data/user/0/com.example.my_app/app_flutter