DartError: Looking up a deactivated widget's ancestor is unsafe

Widgets & Design

I built a component that calls an api when the user clicks the save button. The api call is executed well in the backend, but the flutterflow frontend stops working. This error message is displayed in chrome:

Uncaught (in promise) DartError: Looking up a deactivated widget's ancestor is unsafe.

At this point the state of the widget's element tree is no longer stable.

To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

at Object.throw_ [as throw] (dart_sdk.js:11994:11)

at framework.dart:4743:9

at [_debugCheckStateIsActiveForAncestorLookup] (framework.dart:4756:14)

at framework.StatefulElement.new.dependOnInheritedWidgetOfExactType (framework.dart:4776:12)

at DebugFlutterFlowModelContext.maybeOf (debug_util.dart:34:19)

at get rootModel (flutter_flow_model.dart:93:38)

at get isRouteVisible (flutter_flow_model.dart:98:40)

at Object.debugLogWidgetClass (debug_util.dart:243:23)

at set apiTagSaved (modal_tag_create_edit_model.dart:223:5)

at modal_tag_create_edit_widget._ModalTagCreateEditWidgetState.new.<anonymous> (modal_tag_create_edit_widget.dart:547:35)

at Generator.next (<anonymous>)

at dart_sdk.js:47081:33

at RootZone.runUnary (dartsdk.js:46938:59)

at FutureListener.thenAwait.handleValue (dartsdk.js:42334:29)

at handleValueCallback (dart_sdk.js:42938:49)

at Future.propagateToListeners (dart_sdk.js:42976:17)

at [_completeWithValue] (dart_sdk.js:42817:23)

at async._AsyncCallbackEntry.new.callback (dart_sdk.js:42851:35)

at Object._microtaskLoop (dart_sdk.js:47394:13)

at startMicrotaskLoop (dartsdk.js:47400:13)

at dart_sdk.js:43200:9

Thanks!

What have you tried so far?

I asked chatgpt:

"The error you are encountering is due to attempting to access a widget's context or an ancestor widget after the widget has been deactivated or disposed. The specific problem stems from the fact that you are likely trying to reference an ancestor widget's state (via dependOnInheritedWidgetOfExactType()) when the widget is no longer active."

Since Flutterflow creates the code I cannot implement the code solution offered by chatgpt

Did you check FlutterFlow's Documentation for this topic?
No
1
6 replies