Home > Back-end >  flutter get path without string quotes
flutter get path without string quotes

Time:03-29

I'm using final path = await getExternalStorageDirectory(); to get the external directory path. Then I've to contcat rest of file path to get the text file. But the output of print('${path}/AppLog/Logs/28032022.txt'); are coming like below.

'/storage/emulated/0/Android/data/com.abc.myApp/files'/AppLog/Logs/28032022.txt

I need to achieve the path like /storage/emulated/0/Android/data/com.abc.myApp/files/AppLog/Logs/28032022.txt. How can I remove the '' from the path. Due to this I can't get file.

CodePudding user response:

Use this func to concatenate the filename in the path:

  Future<void> getPathForFileName(String fileName) async {
    final path = (await getExternalStorageDirectory())?.path;
    final finalPath = File('$path/$fileName').path;
    print(finalPath);
  }

Test:

    getPathForFileName("AppLog/Logs/28032022.txt");

prints:

"/storage/emulated/0/Android/data/com.example.flutter_demo/files/AppLog/Logs/28032022.txt"

  • Related