Open SdxCoder opened 4 months ago
The problem is in your widget, but you haven't shared your widget, so I cannot know.
@rrousselGit i here is the attached widget can you have a look kindly.
class StoresMapComponent extends ConsumerWidget {
final StoresTypeToFetch arg;
final bool enableMyLocationButton;
const StoresMapComponent({
super.key,
required this.arg,
this.enableMyLocationButton = true,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
ref.listen(mapControllerProvider(arg), (previous, next) {});
final cameraPosition =
ref.watch(selectedLocationCameraPositionProvider(arg));
final markers = ref.watch(addMarkersProvider(arg));
final isPlayServicesAvailable =
ref.watch(googleServicesProvider).valueOrNull;
return Stack(
children: [
if (isPlayServicesAvailable == null)
const Offstage()
else if (isPlayServicesAvailable)
GoogleMap(
onMapCreated: (controller) {
ref
.read(
getMapControllerProvider(MapToLoad.stores).notifier,
)
.update(IMapController.googleaMaps(controller));
},
zoomControlsEnabled: false,
myLocationButtonEnabled: false,
buildingsEnabled: false,
myLocationEnabled: true,
markers: markers.values.map((e) => e.toGoogleMapMarker()).toSet(),
initialCameraPosition: cameraPosition.toGoogleMapCameraPosition(),
)
else
HuaweiMap(
onMapCreated: (controller) {
ref
.read(
getMapControllerProvider(MapToLoad.stores).notifier,
)
.update(IMapController.huaweiMaps(controller));
},
zoomControlsEnabled: false,
myLocationButtonEnabled: false,
buildingsEnabled: false,
myLocationEnabled: true,
markers: markers.values.map((e) => e.toHuaweiMapMarker()).toSet(),
initialCameraPosition: cameraPosition.toHuaweiMapCameraPosition(),
),
if (enableMyLocationButton)
Align(
alignment: Alignment.bottomRight,
child: Container(
margin: const EdgeInsets.all(Dimens.padding16),
decoration: const BoxDecoration(
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: Color(0x14000000),
blurRadius: 10,
),
],
),
child: FloatingActionButtonWidget(
key: UniqueKey(),
svg: AssetNames.loactionCenterIcon,
color: AppTheme.white,
svgColor: AppTheme.darkGray,
elevation: 0,
onPressed: () {
ref
.read(shouldSetCurrentLocationProvider.notifier)
.update(true);
ref
.read(currentLocationProvider.notifier)
.getCurrentLocation();
},
),
),
),
],
);
}
}
@rrousselGit Can you kindly have a look at the widget and share ur thoughts kindly.
@SdxCoder from what I understand it seems like the StoresMapComponent
widget was already disposed when the onMapCreated
callback is called.
Can you share the parent widget of StoresMapComponent
? The issue might stem from there. You can check if the StoresMapComponent
is built initially but disposed again before the onMapCreated
callback is called.
Describe the bug In our production app from firebase crashlytics, we are getting this exception being logged .i.e Bad state: Cannot use "ref" after the widget was disposed.
Crash Log
To Reproduce We are setting google map controller on onMapCreated callback
And its being used in another provider
Is there any thing wrong with this approach which is causing this error? Can i get help on this ?
Expected behavior This bug shouldn't appear.