Can we access your project?
Current Behavior
I'm using a local app event to propagate updates to a Firestore structure to a subcomponent. If done the required setups:
- Defined the App Event
- Added a Local App Event with Local scope.
- Added an App Event Data parameter using the extension's data type.
The parameter carries the complete updated data structure.
- Registered the handler in the subcomponent
- In the subcomponent's
On Component Init action chain, added a Local App Event Handler for the event.
- Assigned a local Action Block to the handler.
- The Action Block contains one action: update the subcomponent's Component State cache with the App Event's data-type action parameter.
- Added an event trigger from the main component (under a Page)
- In the
Done action chain of the main component, added a Trigger App Event action after the updated data is available.
- Set the App Event Data parameter using the updated data structure.
- The subcomponent handler then replaces its local extension cache with that updated structure.
The event is triggered as expected but upon termination, it throws an error:
DartError: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
The error points to the code in the subcomponent.widget, specifically to the statement that registeres the local app event handler:
@override
void initState() {
super.initState();
_model = createModel(context, () => XCClinicDetailsModel());
// On component load action.
SchedulerBinding.instance.addPostFrameCallback((_) async {
if (!_model.isInitialized) {
_model.xCache = widget!.achievement?.clinicDetails;
_model.attachmentsCache = widget!.achievement?.attachments;
_model.isInitialized = true;
safeSetState(() {});
_model.onSaveClinicDetailsSubscription = FFAppEventService
.instance.localEventsStream
.where((event) => event is OnSaveClinicDetailsEvent)
.cast<OnSaveClinicDetailsEvent>()
.listen((OnSaveClinicDetailsEvent event) async {
// Update the clinic details xCache after a onSaveClinicDetails local app event.
await _model.updateClinicDetailsCache(
context,
data: event.data,
);
});
}
});
_model.textFieldClinicDateTextController ??= TextEditingController();
_model.textFieldClinicDateFocusNode ??= FocusNode();
... (more initializations)
WidgetsBinding.instance.addPostFrameCallback((_) => safeSetState(() {
_model.textFieldClinicDateTextController?.text = dateTimeFormat(
"yMMMd",
widget!.achievement?.clinicDetails?.date,
locale: FFLocalizations.of(context).languageCode,
);
}));
}
Note that my action block does not use the context, however the context is referenced. A defensive check such as: if (!context.mounted) return;
is not included in the generated code.
Note that the error happened in the (new) test environment.
Expected Behavior
I'd expect the generated Local App Event handlers to verify that the receiving component is still mounted before accessing its BuildContext.
Steps to Reproduce
- Create a new Page
- In that page, create a UI component
- In that component, create a UI subcomponent widget
- Set up local app event; use an action block with a single action that updates a Component State variable in the subcomponent using the app event's data parameter.
- The UI component should have a button (Done or Save or whatever) that triggers the app event.
- The OnLoadInit of the subcomponent should define the event handler that invokes the action block.
Reproducible from Blank
Bug Report Code (Required)
IT5TiufluYtPn7xY+KrqafkwoGAsJn07UIIzje5+d0ojHOrpOpl+eOOkaXFJYcukTFVcIWKZ/Wcz+KHJuNnDD8YnHE+ueYNe1ZBITj3zQlmRbrqQPam0VUdfI95WG0yk4bSkmA9QKtRtS1ku706MDe+XQi/cJK7XPjMZO/j9WbL+pVaKLCXNDid7xmNecCfn
Visual documentation
...
Environment
- FlutterFlow version: v7.0.71
- Platform: MacOS
- Browser name and version: Chrome Version 151.0.7922.138 (Official Build) (arm64)
- Operating system and version affected: MacOs 15.6
Additional Information
The crash is not impacting my work as the app event completes before the crash happens and the app continues. However, the crash would most likely generate crashlytics entries in production.
Further testing shows that:
- the error does not happen when running a locally built iOS app on iPad via Xcode
- the error does not happen when running a locally built Flutter web app in Chrome
- The error occurs consistently in the FlutterFlow web test environment in Chrome
Can we access your project?
Current Behavior
I'm using a local app event to propagate updates to a Firestore structure to a subcomponent. If done the required setups:
The parameter carries the complete updated data structure.
On Component Initaction chain, added a Local App Event Handler for the event.Doneaction chain of the main component, added a Trigger App Event action after the updated data is available.The event is triggered as expected but upon termination, it throws an error:
DartError: This widget has been unmounted, so the State no longer has a context (and should be considered defunct).
The error points to the code in the subcomponent.widget, specifically to the statement that registeres the local app event handler:
Note that my action block does not use the context, however the context is referenced. A defensive check such as: if (!context.mounted) return;
is not included in the generated code.
Note that the error happened in the (new) test environment.
Expected Behavior
I'd expect the generated Local App Event handlers to verify that the receiving component is still mounted before accessing its BuildContext.
Steps to Reproduce
Reproducible from Blank
Bug Report Code (Required)
IT5TiufluYtPn7xY+KrqafkwoGAsJn07UIIzje5+d0ojHOrpOpl+eOOkaXFJYcukTFVcIWKZ/Wcz+KHJuNnDD8YnHE+ueYNe1ZBITj3zQlmRbrqQPam0VUdfI95WG0yk4bSkmA9QKtRtS1ku706MDe+XQi/cJK7XPjMZO/j9WbL+pVaKLCXNDid7xmNecCfn
Visual documentation
...
Environment
Additional Information
The crash is not impacting my work as the app event completes before the crash happens and the app continues. However, the crash would most likely generate crashlytics entries in production.
Further testing shows that: