Im new and my question may be stupid but
in class Location i have 2 var :
var latitude;
var longitude;
then :
Location({Key? key, this.latitude , this.longitude}) : super(key: key);
and after some works when I print them I get the value
print(widget.latitude);
print(widget.longitude);
there is no problem here BUT when I want to use these vars in another class like this :
var myLat = Location().latitude;
var myLong = Location().longitude;
the values are NULL
how can get the values the second class too?
2
Answers
When you type
Location()
– you create the new instance of this class. It isn’t connected to the previous instance you were working on. To make this work you need to typeWHERE
location
is the SAME object you created previously. So you need to pass it somehow to the place where you’re trying to access these fields.as you know you have 2 ways:
if you didn’t understand what i mean, please write in comment down.
happy coding…
Moraghebe khodet bash 😉