0

I'm bit new in flutter. And I'm having little error on this matter. I have here a code snippet of where I passed lat and long data from another screen and I want to give acccess on MapsState. But I'm getting a property error The instance member 'widget' can't be accessed in an initializer.

class Maps extends StatefulWidget {
  Maps({this.lati, this.longi}) : super();


  final double lati;
  final double longi;
  
 
  final String title = "Select Location";
 
  @override
  MapsState createState() => MapsState ();
}
 
class MapsState extends State<Maps> {
  


  //
 
  Completer<GoogleMapController> _controller = Completer();
  LatLng _center =  LatLng(widget.lati, widget.longi);
  final Set<Marker> _markers = {};
  LatLng _lastMapPosition = _center;
  MapType _currentMapType = MapType.normal;

Please help.

1 Answers1

0

You can't access your variables when defining another variable. I suggest you to define them but give them values in initState method:

LatLng _center;
@override
void initState(){
  super.initState();
  _center =  LatLng(widget.lati, widget.longi);
}
Mohammad Hosein
  • 457
  • 1
  • 3
  • 11