title: Call state class from widget in flutter
body: <p>I think I have a flawed architecture but I'm struggling to see how/why. I'm very new to flutter, so bear with me please.</p>
  
  <p>I have a map, and a drawer. I'm loading a list of coordinates in the drawer, and I'd like to do stuff on the map once I press one of those coordinates.</p>
  
  <p>So my problem is that I don't know what to call where to be clean code AND working. Of course I could just expose everything to everyone but that wouldn't solve the main issue : me understanding</p>
  
  <p>My map is drawn in the same place as my drawer, so there I already think I'm cheating but I <em>think</em> that's okay. To be honest I'm not even sure that part is really correct.</p>
  
  <p>Drawing the map :</p>
  
  <pre><code>class _MyHomePageState extends State&lt;MyHomePage&gt; {
    int _counter = 0;
    var _map = MapView();
    var _stationService = StationService();
  
    ....
  
  @override
    Widget build(BuildContext context) {
      return MaterialApp(
        home: DefaultTabController(
          length: 4,
          child: Scaffold(
            appBar: AppBar(
              bottom: TabBar(
                tabs: [
                  Tab(icon: Icon(Icons.directions_car)),
                  Tab(icon: Icon(Icons.map)),
                  Tab(icon: Icon(Icons.directions_transit)),
                  Tab(icon: Icon(Icons.directions_bike))
                ],
              ),
              title: Text('Floctta Plus'),
            ),
            drawer: _drawer(),
            body: TabBarView(
              physics: NeverScrollableScrollPhysics(),
              children: [
                IncrementView(),
                _map,
                Icon(Icons.directions_transit),
                Icon(Icons.directions_bike)
              ],
            ),
          ),
        ),
      );
    }
  </code></pre>
  
  <p>In my drawer code :</p>
  
  <pre><code>ListView.builder(
    itemCount: snapshot.data.length,
    itemBuilder: (context, position) {
      return ListTile(
         title: new Text(snapshot.data[position].titleFR),
         leading: new Icon(Icons.pin_drop),
         onTap: () {
           _map.GoToStation();     &lt;&lt;= Here, calling the MapView class
         },
      );
    },
  ),
  
  </code></pre>
  
  <p>All the MapView.dart code </p>
  
  <pre><code>class MapView extends StatefulWidget {
    MapView({Key key}) : super(key: key);
  
  
    void GoToStation() {
      print("I'm reaching this point with success!");
    }
  
    @override
    _MapViewState createState() =&gt; _MapViewState();
  }
  
  class _MapViewState extends State&lt;MapView&gt; {
    CameraPosition _initialPosition =
        CameraPosition(target: LatLng(50.8267018, 4.3532732), zoom: 10.0);
    Completer&lt;GoogleMapController&gt; _controller = Completer();
  
    var _markers;
  
    void AddMarkers(List&lt;Station&gt; stations) {
      setState(() {
        _markers = new List.generate(
            stations.length,
                (index) =&gt; Marker(
              markerId: MarkerId(index.toString()),
              position: new LatLng(double.parse(stations[index].latitude),
                  double.parse(stations[index].longitude)),
              infoWindow: InfoWindow(
                title: stations[index].titleFR,
                snippet: stations[index].city,
              ),
              icon: BitmapDescriptor.defaultMarker,
            ));
      });
    }
  
    void _onMapCreated(GoogleMapController controller) {
      _controller.complete(controller);
    }
  
    @override
    Widget build(BuildContext context) {
      return Stack(
        children: &lt;Widget&gt;[
          GoogleMap(
            onMapCreated: _onMapCreated,
            initialCameraPosition: _initialPosition,
            markers: _markers,
            myLocationEnabled: true,
          ),
        ],
      );
      // );
    }
  }
  </code></pre>
  
  <p>I think there is enough code. </p>
  
  <p>My question is :</p>
  
  <p>Im in my Mapview class now, and I'd like to call <code>AddMarkers</code> that is in my State class. But I can't. I'm not really sure how I'm supposed to proceed.</p>
  
  <p>Should I call the state class directly from the drawer? If so, how?
  Should I call the state from the view class ? If so, how?
  Should I be doing something else entirely? If so, what ?</p>