-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Static Object variable values getting lost / reinitialized #32922
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
That's a known issue when you have relative imports in |
@zoechi so it works fine if you have |
Ok, then this was the issue. |
I wasn't saying it was working fine, I'm asking you if it works fine when you do that import? It sounded like you were saying in your first post that this is why the static variables weren't working. |
It was a guess. It's a common issue. |
I never knew that. Definitely should have some kind of warning for this in Flutter projects. Still I think this issue still stands as it's unexpected behavior. |
Well |
For me it works only if for local files I leave out the |
@kosta @danchintz might be a different problem. I'd suggest creating a new issue with a reproduction project, Dart version, ... if possible. |
I have put together two simple self-explanatory app to demonstrate the issue. (1)
Which prints out: So far so good. Then in the MyHomePage::build I call
Which prints out a re-initialized value: This the version I am running: (2) Here is a modified version of the app that uses a global variable instead of the static property. The issue is the same: I/flutter ( 5778): (1) MyApp::build [Initial Value] |
@kostaa |
Agree, it's a recurring problem. It was always a problem, but it's intensified since Flutter put the main file into |
Duplicate of #33076. |
My issue was I renamed a file from 'Storage' to 'storage'. But in main, it was imported 'Storage' so other files which were using |
@KLD just encountered the exact same issue in Dart 3.4.4. Thanks for the time saver. I had a dart file called |
It's not a bug (it's working as intended), but it is an annoyance. The problem is that the language, and the compiler even, cannot really determine if the file system is case sensitive. (What the language could potentially do is to disallow having multiple files that differ only in casing. It has to be casing of the entire path, because |
Dart SDK version: 2.0.0-dev.47.0.flutter-f76dad0adc
OS: Tested on both Linux (Elementary OS 0.4) and Mac OS High Sierra 10.13.3
Currently the static keyword doesn't seem to be working as it should whenever you have a List of objects. Whenever I check the length of the static list in another class which wasn't the same class where I added an item to the list, the length returns 0.
Example:
I have four dart classes listed below:
Whenever I add in shop.dart multiple items to my static list and then check the same static list in cart.dart, it returns nothing in the list.
I have checked Stack Overflow and I've found people with similar issues: https://stackoverflow.com/questions/45772318/flutter-dart-static-variables-lost-keep-getting-reinitialized
The text was updated successfully, but these errors were encountered: