Repository navigation
Asset paths are inconsistent #84346
Description
Activity
- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Jun 11, 2021 Hi @hitman-codehq
The issue is your pubspec.yaml, you're missing path forvar assetContent = await rootBundle.loadString('my_asset.txt');and place themy_asset.txtfile in the root directory of your projectminimal code sample
import 'package:flutter/material.dart'; import 'package:flutter/services.dart' show rootBundle; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( // This is the theme of your application. // // Try running your application with "flutter run". You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // "hot reload" (press "r" in the console where you ran "flutter run", // or simply save your changes to "hot reload" in a Flutter IDE). // Notice that the counter didn't reset back to zero; the application // is not restarted. primarySwatch: Colors.blue, ), home: MyHomePage(title: 'Flutter Demo Home Page'), ); } } class MyHomePage extends StatefulWidget { MyHomePage({Key? key, required this.title}) : super(key: key); // This widget is the home page of your application. It is stateful, meaning // that it has a State object (defined below) that contains fields that affect // how it looks. // This class is the configuration for the state. It holds the values (in this // case the title) provided by the parent (in this case the App widget) and // used by the build method of the State. Fields in a Widget subclass are // always marked "final". final String title; @override _MyHomePageState createState() => _MyHomePageState(); } class _MyHomePageState extends State<MyHomePage> { int _counter = 0; void _readAsset() async { try { print('*** Test #1: Calling loadString() without path'); var assetContent = await rootBundle.loadString('my_asset.txt'); print('*** Success ($assetContent)!'); } on FlutterError { print('*** Failed, exception thrown'); } try { print('***'); print('*** Test #2: Calling loadString() with path'); var assetContent = await rootBundle.loadString('assets/my_asset.txt'); print('*** Success ($assetContent)!'); } on FlutterError { print('*** Failed, exception thrown'); } } @override Widget build(BuildContext context) { // This method is rerun every time setState is called, for instance as done // by the _incrementCounter method above. // // The Flutter framework has been optimized to make rerunning build methods // fast, so that you can just rebuild anything that needs updating rather // than having to individually change instances of widgets. return Scaffold( appBar: AppBar( // Here we take the value from the MyHomePage object that was created by // the App.build method, and use it to set our appbar title. title: Text(widget.title), ), body: Center( // Center is a layout widget. It takes a single child and positions it // in the middle of the parent. child: Column( // Column is also a layout widget. It takes a list of children and // arranges them vertically. By default, it sizes itself to fit its // children horizontally, and tries to be as tall as its parent. // // Invoke "debug painting" (press "p" in the console, choose the // "Toggle Debug Paint" action from the Flutter Inspector in Android // Studio, or the "Toggle Debug Paint" command in Visual Studio Code) // to see the wireframe for each widget. // // Column has various properties to control how it sizes itself and // how it positions its children. Here we use mainAxisAlignment to // center the children vertically; the main axis here is the vertical // axis because Columns are vertical (the cross axis would be // horizontal). mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text( 'You have pushed the button this many times:', ), Text( '$_counter', style: Theme.of(context).textTheme.headline4, ), ], ), ), floatingActionButton: FloatingActionButton( onPressed: _readAsset, tooltip: 'Increment', child: Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); } }
[ +2 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:56935/4P_9Z-UaY28=/ [ +704 ms] The Flutter DevTools debugger and profiler on Windows is available at: http://127.0.0.1:9105?uri=http%3A%2F%2F127.0.0.1%3A56935%2F4P_9Z-UaY28%3D%2F [+4738 ms] flutter: *** Test #1: Calling loadString() without path [ +14 ms] flutter: *** Success (Hello world)! [ +1 ms] flutter: *** [ ] flutter: *** Test #2: Calling loadString() with path [ +1 ms] flutter: *** Success (Hello world)
pubspec.yaml
name: asset_example description: A new Flutter project. # The following line prevents the package from being accidentally published to # pub.dev using `pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. # A version number is three numbers separated by dots, like 1.2.43 # followed by an optional build number separated by a +. # Both the version and the builder number may be overridden in flutter # build by specifying --build-name and --build-number, respectively. # In Android, build-name is used as versionName while build-number used as versionCode. # Read more about Android versioning at https://developer.android.com/studio/publish/versioning # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html version: 1.0.0+1 environment: sdk: ">=2.12.0 <3.0.0" dependencies: flutter: sdk: flutter # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 dev_dependencies: flutter_test: sdk: flutter # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec # The following section is specific to Flutter. flutter: # The following line ensures that the Material Icons font is # included with your application, so that you can use the icons in # the material Icons class. uses-material-design: true # To add assets to your application, add an assets section, like this: assets: - assets/my_asset.txt - my_asset.txt # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware. # For details regarding adding assets from package dependencies, see # https://flutter.dev/assets-and-images/#from-packages # To add custom fonts to your application, add a fonts section here, # in this "flutter" section. Each entry in this list should have a # "family" key with the font family name, and a "fonts" key with a # list giving the asset and other descriptors for the font. For # example: # fonts: # - family: Schyler # fonts: # - asset: fonts/Schyler-Regular.ttf # - asset: fonts/Schyler-Italic.ttf # style: italic # - family: Trajan Pro # fonts: # - asset: fonts/TrajanPro.ttf # - asset: fonts/TrajanPro_Bold.ttf # weight: 700 # # For details regarding fonts from package dependencies, # see https://flutter.dev/custom-fonts/#from-packages
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- addedr: invalidIssue is closed as not validIssue is closed as not validand removedin triagePresently being triaged by the triage teamPresently being triaged by the triage team
on Jun 11, 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.
@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.
- addedin triagePresently being triaged by the triage teamPresently being triaged by the triage teamand removedr: invalidIssue is closed as not validIssue is closed as not valid
on Jul 9, 2021 Hi @hitman-codehq
I just tried on macOS too, error is thrown since you're not providing correct path[ +6 ms] Connected to _flutterView/0x7fbc83050820. [ +2 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 macOS is available at: http://127.0.0.1:50001/A4B3rk64kp4=/ [ +797 ms] The Flutter DevTools debugger and profiler on macOS is available at: http://127.0.0.1:9100?uri=http%3A%2F%2F127.0.0.1%3A50001%2FA4B3rk64kp4%3D%2F [+14193 ms] flutter: *** Test #1: Calling loadString() without path [ +13 ms] flutter: *** Failed, exception thrown [ ] flutter: *** [ ] flutter: *** Test #2: Calling loadString() with path [ +2 ms] flutter: *** Success (Hello world)!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
assets: - my_asset.txt - assets/my_asset.txtThe error is gone on macOS too
[ ] An Observatory debugger and profiler on macOS is available at: http://127.0.0.1:50151/0Wba8YDUcFI=/ [ +763 ms] The Flutter DevTools debugger and profiler on macOS is available at: http://127.0.0.1:9102?uri=http%3A%2F%2F127.0.0.1%3A50151%2F0Wba8YDUcFI%3D%2F [+114152 ms] flutter: *** Test #1: Calling loadString() without path [ +12 ms] flutter: *** Success (Hello world)! [ ] flutter: *** [ ] flutter: *** Test #2: Calling loadString() with path [ ] flutter: *** Success (Hello world)!
- addedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on Jul 12, 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:
*** Test #1: Calling loadString() without path *** Success (Hello world)! *** *** Test #2: Calling loadString() with path *** Success (Hello world)!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.
- removedwaiting for responseThe Flutter team cannot make further progress on this issue until the original reporter respondsThe Flutter team cannot make further progress on this issue until the original reporter responds
on 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
- removedtriaged-engineTriaged by Engine teamTriaged by Engine teamteam-toolOwned by Flutter Tool teamOwned by Flutter Tool team
on 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.- addedteam-toolOwned by Flutter Tool teamOwned by Flutter Tool teamand removedengineflutter/engine related. See also e: labels.flutter/engine related. See also e: labels.
on Aug 15, 2023 @andrewkolos can you verify if this is still an issue, and then either close or mark triaged-tool with a priority?
I have not tried to reproduce the issue, but here is the short version of my understanding from skimming it...
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).- addedP2Important issues not at the top of the work listImportant issues not at the top of the work listtriaged-toolTriaged by Flutter Tool teamTriaged by Flutter Tool team
on Aug 15, 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. 👍
- addedtool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.Issues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.
on Jul 10, 2025 - added a commit that references this issue
on Aug 21, 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.- locked as resolved and limited conversation to collaborators
on Sep 4, 2026

Steps to Reproduce
flutter create asset_example.asset_example.zip
Expected results:
The code called by clicking on the FAB, in lib/main.dart:_readAssest(), should print:
Actual results:
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
Many thanks for your help!