LateInitializationError - FlutterFlowDynamicModels

Troubleshooting

The problem arose when I had a place picker, a list view with item spacing that displayed a list of a widget (widget A), and that widget also had another widget (Widget B) inside. In code, the model for widget A was generated with something like this:

class WidgetAModel
    extends FlutterFlowModel<WidgetAWidget> {

  ///  State fields for stateful widgets in this component.

  // Model for widgetB component.
  late WidgetBModel widgetBModel1;

  @override
  void initState(BuildContext context) {
    widgetBModel1 =
        createModel(context, () => WidgetBModel());   
  }

  @override
  void dispose() {
    widgetBModel1.dispose();
  }

When I used the place picker and then clicked on a button that had goNamed to any other page, an error appeared in the dispose method for widget A, stating that WidgetBModel1 wasn't initialized. But this only happens if I use the place picker. In my opinion, this was a FlutterFlow bug. Anyway, what I did was not use widgetB, but instead placed everything directly in widgetA. This error didn't appear in test mode either, but it did in Android Studio. Likewise, if instead of using goNamed I used pushNamed nothing would happen at first, but if I then used goNamed at some point the error would appear in the dispose method.

LateInitializationError: Field 'widgetBmodel1' has not been initialized.
What have you tried so far?

I tried to dig deeper into the code and I think the error is inside the updateActiveKeys function which is inside flutterflow_model.dart, I get there because in the page model there is:

late FlutterFlowDynamicModels<WidgetAModel>
      widgetAModels;

After using loggings i noticed than after clicking in the placed search in the place picker, aparently _updateActiveKeys by one of the widgets createds in the list view, eliminating all the others models in _childrenModels. Then all the widgets are added again with the same key but when making dispose this models added arent the ones that were initiated. Still I dont know how fixed it.

Did you check FlutterFlow's Documentation for this topic?
No
3
5 replies