googlemap - searchMapPlaceWidget inside bottomsheetwidget

216 views
Skip to first unread message

Error Place

unread,
May 4, 2020, 6:34:15 AM5/4/20
to Flutter Development (flutter-dev)
hi guys. i am setting up a map inside a bottomsheet so the user can search a location and set their location by adding a marker . but for some reason the marker is not getting added after search is done and instead it shows up when the bottomsheet is disposed . and i am getting this message inside dart console



[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: setState() called after dispose(): _SearchMapPlaceWidgetState#4107e(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers)
This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
#0      State.setState.<anonymous clos<…>

does anyone know what i am doing wrong with the state?

thank you all in advenced

Souvik Dutta

unread,
May 4, 2020, 6:55:08 AM5/4/20
to Error Place, Flutter Development (flutter-dev)
Show us your setState() code.

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/f9776006-4b96-4662-9dfd-23a0b0f038cb%40googlegroups.com.

Souvik Dutta

unread,
May 4, 2020, 6:55:37 AM5/4/20
to Error Place, Flutter Development (flutter-dev)
That is the place where you used setState in your code.

Souvik flutter dev

On Mon, May 4, 2020, 4:04 PM Error Place <reza7....@gmail.com> wrote:
--

Error Place

unread,
May 4, 2020, 6:56:31 AM5/4/20
to Flutter Development (flutter-dev)
SearchMapPlaceWidget(
placeType: PlaceType.establishment,
language: 'se',
apiKey: kGoogleApiKey,
onSelected: (place)async{


final geolocation = await place.geolocation;

final chosenPlace = Marker(
markerId: MarkerId('chosen-location'),
icon: await BitmapDescriptor.defaultMarker,
position: geolocation.coordinates,

);


GoogleMapController controller = await _mapController.future;
setState(() {
_selectedPlace = place;
_markers.add(chosenPlace);
});


controller.animateCamera(CameraUpdate.newLatLng(geolocation.coordinates));
controller.animateCamera(CameraUpdate.newLatLngBounds(geolocation.bounds, 50));

},
),

Error Place

unread,
May 4, 2020, 7:01:06 AM5/4/20
to Flutter Development (flutter-dev)
my searchMapPlaceWidget and google maps are childrens of a stack widget inside a bottomsheet


Den måndag 4 maj 2020 kl. 12:34:15 UTC+2 skrev Error Place:

Souvik Dutta

unread,
May 4, 2020, 7:01:55 AM5/4/20
to Error Place, Flutter Development (flutter-dev)
Can you share this whole class?

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Souvik Dutta

unread,
May 4, 2020, 7:04:21 AM5/4/20
to Error Place, Flutter Development (flutter-dev)
Okay I think you will have to wrap setState() inside if (this.mounted){
set state((){})}

Souvik flutter dev

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Error Place

unread,
May 4, 2020, 7:11:25 AM5/4/20
to Flutter Development (flutter-dev)
ive tried mounted but the results is the same!this is the whole message i am getting inside the console witch tells me what i can do!
[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: setState() called after dispose(): _SearchMapPlaceWidgetState#70762(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers)
This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

To unsubscribe from this group and stop receiving emails from it, send an email to flutt...@googlegroups.com.

Souvik Dutta

unread,
May 4, 2020, 7:17:07 AM5/4/20
to Error Place, Flutter Development (flutter-dev)
Are there any other setState() in the code?

To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/8960e7f0-68d6-42aa-bc0f-e4fac8bdd502%40googlegroups.com.

Error Place

unread,
May 4, 2020, 7:19:36 AM5/4/20
to Flutter Development (flutter-dev)
i have two other setState in that same page which belongs to two other functions?

_submit() async {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();

setState(() {
_isLoading = true;
});


_handleImageFromGallery() async {
File imageFile = await ImagePicker.pickImage(source: ImageSource.gallery);
if (imageFile != null) {
setState(() {
_profileImage = imageFile;
});
}
}
Den måndag 4 maj 2020 kl. 12:34:15 UTC+2 skrev Error Place:

Souvik Dutta

unread,
May 4, 2020, 7:26:07 AM5/4/20
to Error Place, Flutter Development (flutter-dev)
I think yu will have to check mounted in all those other two setState().

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.

Error Place

unread,
May 4, 2020, 7:33:08 AM5/4/20
to Flutter Development (flutter-dev)
tired that too but the results is still the same and the same message is shown ! i am going to try to set a dispose function for the bottomsheetwidget and see if it works
thank you for your effort Souvik


Den måndag 4 maj 2020 kl. 12:34:15 UTC+2 skrev Error Place:
Reply all
Reply to author
Forward
0 new messages