I have got the following Text( ... ) widget in my Flutter application
Text(
data['location'],
style: TextStyle(
fontSize: 40,
letterSpacing: 2,
color: Colors.white
)
However, it keeps showing me an error that the data['location'] cannot be accessed, as it can be null. I guess it has to do something with Dart's null safety checks
The flow of my code is something like this:
The data object that I am accessing in the Text( ... ) widget is declared above like this:
Object? data;
Afterwards, when I pass data to this screen from another screen, I use the data object declared above and do the following assignment:
data = ModalRoute.of(context)!.settings.arguments;
And, finally, in the end, I access this data object in my Text( ... ) widget
What should I do to avoid this error?