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

#lesson 28 Error: Field 'time' should be initialized because its type 'String' doesn't allow null. String time; // the time in that location #50

Open
akashgreninja opened this issue Oct 24, 2021 · 2 comments

Comments

@akashgreninja
Copy link

Guys,Im getting this error Error: Field 'time' should be initialized because its type 'String' doesn't allow null.
String time; // the time in that location please can you give me a fix?
^^^^

@hanabinoir
Copy link

Hope it make sense after two month.

For the latest version of flutter, it requires a late keyword before String type:

late String time;

There are some advanced solutions, but it might be difficult for beginners to rewrite the whole logic:
https://dart.dev/null-safety/understanding-null-safety

@ayowilfred95
Copy link

setting String time to late will not fetch the data.
You can create your constructor this way.

World time({required this location, required this.glag, required this.url}):time=' ' ; // Initialize time with empty string.

And that solve the error.
Remember

time = time.now(); //. time has been assigned a function

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

3 participants