Severity
High — Flutter anti-pattern causing form-state loss and redundant network work.
Problem
KycRegistrationPersonalStep and KycRegistrationAddressStep are StatelessWidgets that hold a GlobalKey<FormState> as an instance field:
lib/screens/kyc/steps/registration/steps/kyc_registration_personal_step.dart:32
lib/screens/kyc/steps/registration/steps/kyc_registration_address_step.dart:25
_buildStep (kyc_registration_page.dart) is called inside PageView(children: KycRegistrationStep.values.map(_buildStep).toList()), which runs on every rebuild of _KycRegistrationViewState — including every BlocBuilder<KycRegistrationSubmitCubit> / BlocBuilder<KycRegistrationStepCubit> state change. Each rebuild constructs fresh step widgets with fresh GlobalKeys.
Effect
A GlobalKey is bound to exactly one element. When the step widget is rebuilt with a new key, Flutter treats it as a different widget and rebuilds the Form element and its State from scratch:
- the
FormState / validation state is lost;
- the
CountryField's FutureBuilder state is recreated → initState re-runs → the country list is re-fetched.
(TextEditingControllers survive because they live in the persistent _KycRegistrationViewState; the form/validation state and the CountryField state do not.)
Suggested fix
Convert the two step widgets to StatefulWidget and hold the GlobalKey in their State — as KycNationalityView and SettingsEditAddressView already do correctly.
Context
Found during a deep audit of the KYC country/nationality data path (see #519).
Severity
High — Flutter anti-pattern causing form-state loss and redundant network work.
Problem
KycRegistrationPersonalStepandKycRegistrationAddressStepareStatelessWidgets that hold aGlobalKey<FormState>as an instance field:lib/screens/kyc/steps/registration/steps/kyc_registration_personal_step.dart:32lib/screens/kyc/steps/registration/steps/kyc_registration_address_step.dart:25_buildStep(kyc_registration_page.dart) is called insidePageView(children: KycRegistrationStep.values.map(_buildStep).toList()), which runs on every rebuild of_KycRegistrationViewState— including everyBlocBuilder<KycRegistrationSubmitCubit>/BlocBuilder<KycRegistrationStepCubit>state change. Each rebuild constructs fresh step widgets with freshGlobalKeys.Effect
A
GlobalKeyis bound to exactly one element. When the step widget is rebuilt with a new key, Flutter treats it as a different widget and rebuilds theFormelement and itsStatefrom scratch:FormState/ validation state is lost;CountryField'sFutureBuilderstate is recreated →initStatere-runs → the country list is re-fetched.(
TextEditingControllers survive because they live in the persistent_KycRegistrationViewState; the form/validation state and theCountryFieldstate do not.)Suggested fix
Convert the two step widgets to
StatefulWidgetand hold theGlobalKeyin theirState— asKycNationalityViewandSettingsEditAddressViewalready do correctly.Context
Found during a deep audit of the KYC country/nationality data path (see #519).