Repository navigation
Asset paths are inconsistent #84346
Description
Steps to Reproduce
- Run
flutter create asset_example. - Update the files as follows: Extract the attached file:
asset_example.zip - This file adds an asset called my_asset.txt and some code to try and read it in lib/main.dart
- Run the build on Windows with "flutter run" and select the target Windows (desktop)
- Click on the FAB and look at the console output
Expected results:
The code called by clicking on the FAB, in lib/main.dart:_readAssest(), should print:
flutter: *** Test #1: Calling loadString() without path
flutter: *** Success (Hello world)!
flutter: ***
flutter: *** Test #2: Calling loadString() with path
flutter: *** Success (Hello world)!Actual results:
flutter: *** Test #1: Calling loadString() without path
flutter: *** Failed, exception thrown
flutter: ***
flutter: *** Test #2: Calling loadString() with path
flutter: *** Success (Hello world)!This only happens on Windows. On MacOS, Android, iOS and Web (both on Windows and MacOS) it doesn't matter whether you call loadString('my_asset.txt') or loadString('assets/my_asset.txt'). The behaviour should be consistent across all platforms. It took quite a bit of digging to figure out why a 3rd party plugin wasn't working on Windows due to this problem!
If you now type "flutter run" and instead select Chrome (chrome) as the target, you'll see that both calls to loadString() work.
It doesn't matter whether I add the asset to the pubspec.yaml by using the full path (- assets/my_asset.txt) or only the filename (- my_asset.txt): the results are the same. I have to use the full path in loadString() for it to work on Windows but on all other platforms, just the filename is enough.
Logs
[Snipped excessive output]
[ +2 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/assets
[ +2 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/**assets/my_asset.txt**
[ +3 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/FontManifest.json
[ +2 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/fonts
[ +1 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/fonts/MaterialIcons-Regular.otf
[ +24 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/kernel_blob.bin
[ +488 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/NOTICES
[ +280 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages
[ +1 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages/cupertino_icons
[ +2 ms] -- Installing: D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages/cupertino_icons/assets
[ +2 ms] -- Installing:
D:/Source/Flutter/asset_example/build/windows/runner/Debug/data/flutter_assets/packages/cupertino_icons/assets/CupertinoIcons.ttf
[ +39 ms] FinalizeBuildStatus:
[ +1 ms] Die Datei "x64\Debug\INSTALL\INSTALL.tlog\unsuccessfulbuild" wird gelöscht.
[ ] Aktualisieren des Timestamps von "x64\Debug\INSTALL\INSTALL.tlog\INSTALL.lastbuildstate".
[ ] Die Erstellung von Projekt "D:\Source\Flutter\asset_example\build\windows\INSTALL.vcxproj" ist abgeschlossen (Standardziele).
[ ] Der Buildvorgang wurde erfolgreich ausgeführt.
[ +1 ms] 0 Warnung(en)
[ ] 0 Fehler
[ ] Verstrichene Zeit 00:00:47.41
[ +39 ms] Building Windows application... (completed in 53,5s)
[+1925 ms] Observatory URL on device: http://127.0.0.1:60977/jbP5Nn4c03M=/
[ +5 ms] Caching compiled dill
[ +66 ms] Connecting to service protocol: http://127.0.0.1:60977/jbP5Nn4c03M=/
[ +212 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:60977/jbP5Nn4c03M=/.
[ +80 ms] DDS is listening at http://127.0.0.1:60980/j2QIYS1vN84=/.
[ +73 ms] Successfully connected to service protocol: http://127.0.0.1:60977/jbP5Nn4c03M=/
[ +23 ms] DevFS: Creating new filesystem on the device (null)
[ +21 ms] DevFS: Created new filesystem on the device (file:///C:/Users/Colin/AppData/Local/Temp/asset_examplecadd69ff/asset_example/)
[ +2 ms] Updating assets
[ +91 ms] Syncing files to device Windows...
[ +3 ms] <- reset
[ ] Compiling dart to kernel with 0 updated files
[ +3 ms] <- recompile package:asset_example/main.dart 76b568cb-07ad-4824-bfb4-e0a0852698a8
[ ] <- 76b568cb-07ad-4824-bfb4-e0a0852698a8
[ +249 ms] Updating files.
[ +1 ms] DevFS: Sync finished
[ ] Syncing files to device Windows... (completed in 258ms)
[ ] Synced 0.0MB.
[ +2 ms] <- accept
[ +7 ms] Connected to _flutterView/0x16d800d0ec0.
[ +4 ms] Flutter run key commands.
[ +1 ms] r Hot reload.
[ +1 ms] R Hot restart.
[ ] h Repeat this help message.
[ ] d Detach (terminate "flutter run" but leave application running).
[ ] c Clear the screen
[ ] q Quit (terminate the application on the device).
[ ] Running with sound null safety
[ ] An Observatory debugger and profiler on Windows is available at: http://127.0.0.1:60980/j2QIYS1vN84=/
[+1596 ms] The Flutter DevTools debugger and profiler on Windows is available at:
http://127.0.0.1:9108?uri=http%3A%2F%2F127.0.0.1%3A60980%2Fj2QIYS1vN84%3D%2F
[+2089 ms] flutter: *** Test #1: Calling loadString() without path
[ +10 ms] flutter: *** Failed, exception thrown
[ ] flutter: ***
[ ] flutter: *** Test #2: Calling loadString() with path
[ +1 ms] flutter: *** Success (Hello world)!d:\Source\Flutter\asset_example>flutter analyze
Analyzing asset_example...
No issues found! (ran in 19.3s)
d:\Source\Flutter\asset_example>flutter doctor -v
[√] Flutter (Channel stable, 2.2.1, on Microsoft Windows [Version 10.0.19041.1052], locale de-DE)
• Flutter version 2.2.1 at d:\Coding\Flutter
• Framework revision 02c026b03c (2 weeks ago), 2021-05-27 12:24:44 -0700
• Engine revision 0fdb562ac8
• Dart version 2.13.1
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at d:\Coding\Android\SDK
• Platform android-30, build-tools 30.0.2
• Java binary at: C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
• Java version Java(TM) SE Runtime Environment (build 1.8.0_291-b10)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.10.0)
• Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
• Visual Studio Community 2019 version 16.10.31321.278
• Windows 10 SDK version 10.0.19041.0
[!] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
[√] VS Code, 64-bit edition (version 1.56.2)
• VS Code at C:\Program Files\Microsoft VS Code
• Flutter extension version 3.23.0
[√] Connected device (3 available)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19041.1052]
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.77
• Edge (web) • edge • web-javascript • Microsoft Edge 91.0.864.41
! Doctor found issues in 1 category.
Many thanks for your help!
Activity
TahaTesser commentedon Jun 11, 2021
Hi @hitman-codehq
The issue is your pubspec.yaml, you're missing path for
var assetContent = await rootBundle.loadString('my_asset.txt');and place themy_asset.txtfile in the root directory of your projectminimal code sample
pubspec.yaml
Closing, as this isn't an issue with Flutter itself. If you disagree, please write in the comments and I will reopen it.
Thank you
hitman-codehq commentedon Jun 28, 2021
Hello @TahaTesser, just getting back to this issue again.
Yes your solution would of course work, but the problem here is that the solution is only required on Windows. It works just fine on the other platforms that are supported by Flutter without having to change my .dart code or move the asset. So it should also work on Windows without having to do that.
So it would be appreciated if you could re-open this issue and address it, as I lost quite a bit of time due to this, and other people have as well.
Many thanks.
hitman-codehq commentedon Jul 6, 2021
@TahaTesser can we re-open this issue please? I spent quite some time making a reproducible test case and it would be nice to see it fixed.
TahaTesser commentedon Jul 12, 2021
Hi @hitman-codehq
I just tried on macOS too, error is thrown since you're not providing correct path
await rootBundle.loadString('my_asset.txt');is looking for a file in app root directory hence the errorIf you correct the path and put file in root directory too
The error is gone on macOS too
hitman-codehq commentedon Jul 13, 2021
Hello @TahaTesser I have done some more tests and it seems that with Flutter 2.2.3 the behaviour has changed. On MacOS, the failure is also happening now. And that is ok, because it is the same result as on Windows.
So good, with Flutter 2.2.3 it is now working the same on Windows and MacOS for native Flutter apps. But let's try it on Windows or MacOS with Chrome as the target:
Oh no! They both work! But they shouldn't. Why? Because the behaviour should be the same on all platforms. That's the whole point of Flutter. Either both tests work on Windows, MacOS and Chrome (plus Android and iOS) or test #1 fails on all platforms and test #2 succeeds.
Please don't tell me to edit my pubspec.yaml or main.dart because that's missing the point. It's not what this issue is about.
Hopefully I've managed to explain better what the actual problem is.
Interestingly there are no mentions of path or asset related issues on https://github.com/flutter/flutter/wiki/Hotfixes-to-the-Stable-Channel but the behaviour has definitely changed.
hitman-codehq commentedon Jul 13, 2021
A little bit more information why this is important. Have a look at this plugin:
https://pub.dev/packages/flutter_dotenv
I was using this and it was working if you follow its instructions on MacOS and Chrome. But it wasn't working on Windows. On the website of the plugin, lots of people are asking when Windows will be supported. But the thing is: it already is supported. But it wasn't working because Flutter on Windows was working differently to other platforms so the instructions weren't working.
This highlights the importance of Flutter behaving identically on different platforms.
22 remaining items
flutter-triage-bot commentedon Aug 15, 2023
Issue is assigned to multiple teams (engine, tool). Please ensure the issue has only one
team-*label at a time. Usefyi-*labels to have another team look at the issue without reassigning it.christopherfujino commentedon Aug 15, 2023
@andrewkolos can you verify if this is still an issue, and then either close or mark triaged-tool with a priority?
andrewkolos commentedon Aug 15, 2023
I was able to repro the issue using these steps.
my_asset.txtwas loadable in web, but not in Android or MacOS (and assumably all other platforms as well).hitman-codehq commentedon Aug 16, 2023
Thanks for looking into this. I remember I lost a bit of time due to this inconsistent behaviour, and then put quite a bit of effort into making a reproducible test case. It's only a small bug, but it would be nice to see it fixed. 👍
[flutter_tools] Restrict WebAssetServer source resolution to source m…
github-actions commentedon Sep 4, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.