Answers for "static values turn to null flutter"

0

static values turn to null flutter

It seems that Flutter and Dart have issue to find
the same instance for static (global) variable if
the import starts with: "package:your_app_package/file.dart".

So let say you want to have static variable
(myStaticVariable) in your main.dart file, where you
have MyApp class. And let say that you want to get that static
variable in some different .dart file in your project,
by calling it with MyApp.myStaticVariable.

In that case if you import main.dart with
"import package:your_app_package/main.dart" the variable will
have "null" value , even if it has been initialised before!

If you import main.dart with just "import main.dart"
(if the files are in the same directory) or "import ../main.dart"
(if your file is one directory dipper then main.dart),
you will get the right value for MyApp.myStaticVariable.
Posted by: Guest on February-24-2022

Code answers related to "Dart"

Browse Popular Code Answers by Language