Mapbox: createState function for MapWidget returned an old or invalid state instance

16 Views Asked by At

I'm fairly new to Flutter and MapBox thus sorry if this question is too naive

I am creating an app where there is a page that looks like this:

Column
- Expanded
-- ListView
--- MapBox Map Widget
--- Many Rows

When I scroll down till the Map disappears, and then when I scroll back, I get this error:

════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building _SelectionKeepAlive(state: _SelectionKeepAliveState#b960e):
The createState function for MapWidget returned an old or invalid state instance: MapWidget, which is not null, violating the contract for createState.
'package:flutter/src/widgets/framework.dart':
Failed assertion: line 5573 pos 7: 'state._widget == null'

I know this might be caused by the ListView destroying and recreating the map view, but how to solve this error ?

Another solution that I am thinking about but haven't tried yet is to use a Scroll View instead of List View because a Scroll View seems to do not destroy the map view when it's hidden.

Is there a solution without resorting to a ScrollView ?

Here is the part of code in my build function where the map is created:

newTripPlanListView.insert(0,Padding(padding: EdgeInsets.all(4.0), child: 
        ConstrainedBox(constraints: new BoxConstraints(maxHeight: 500), child: MapWidget(
          key: ValueKey("TravelMap"),
          onMapCreated: (map) {
            log("Map is created");
            travelMap = map;
            
          travelMap!.annotations.createPointAnnotationManager().then((pointAnnotationManager) async {
              // some code to set up annotations and move the camera
            });
          },
      ),),));
0

There are 0 best solutions below