Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-nullable instance field '_bmi' must be initialized. #17

Open
hodakl099 opened this issue Feb 26, 2022 · 8 comments
Open

Non-nullable instance field '_bmi' must be initialized. #17

hodakl099 opened this issue Feb 26, 2022 · 8 comments

Comments

@hodakl099
Copy link

if you have this issue, mark the variable _bmi with late key word.
late double _bmi;

@deepraj02
Copy link

Same here tried every trick in the dictionary didn't worked!

@hodakl099
Copy link
Author

@deepraj02
mark the property late this error because of null safety for more information read https://dart.dev/null-safety
i handled it this way
late double _bmi;

@deepraj02
Copy link

Thank you soo much brother, however I tried this method too but at that time my app crashed
Anyways Thank you again..💪

@tobe-nna
Copy link

tobe-nna commented Aug 1, 2022

in Calculatorbrain class make sure that in calculateBMI function, bmi was aslo initialised as _bmi

@hacker0id
Copy link

this issue has come up with latest updates in Dart.

@hodakl099
Copy link
Author

@hacker0id can you post the error

@hacker0id
Copy link

@hacker0id can you post the error

even when I set the property to late it still shows late initialisation error and the only solution I came around was to initialise the variable

@hodakl099
Copy link
Author

The reason of this error that when you use a late variable before its initialization.
it's depends on your use case, when you need to use late initializing. if you use late initializing var make sure to assign to a value before passing it to a widget.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants