Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 在Flatter应用程序中找到资产文件的路径_Flutter_Dart_Flutter Dependencies - Fatal编程技术网

Flutter 在Flatter应用程序中找到资产文件的路径

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)中使用它 谢谢因为您的资产中包含

我使用的软件包(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)中使用它


谢谢

因为您的资产中包含了应用程序,所以您必须将文件从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