Cannot submit in List and Group Fields in form_bloc_web when everything is empty
aideric opened this issue · 1 comments
aideric commented
Step to reproduce:
- Press the List and Group Fields in form_bloc_web.
- Press the submit button.
This bug occur due to
form_bloc/packages/form_bloc/lib/src/blocs/field/field_bloc.dart
Lines 790 to 791 in 60521fc
When the list is empty, the list.every function return true. Since the members value in ListFieldFormBloc is empty in initial, the areFieldBlocsValidating return true, the field's isValidating = true. So ListFieldFormBloc cannot be submitted.
This can be fix by change it to the following
static bool areFieldBlocsValidating(Iterable<FieldBloc> fieldBlocs) =>
fieldBlocs.isEmpty ? false : fieldBlocs.every(_isFieldBlocValidating);
enzo-santos commented
Based on OP's suggestion, I suggest a temporary fix for current users by creating a new ListFieldBloc
subclass with the following implementation:
import 'package:flutter_form_bloc/flutter_form_bloc.dart' as ffb;
class _ListFieldBloc<T extends ffb.FieldBloc, ExtraData> extends ffb.ListFieldBloc<T, ExtraData> {
_ListFieldBloc({super.name, super.fieldBlocs = const [], super.extraData});
@override
ffb.ListFieldBlocState<T, ExtraData> get state {
final ffb.ListFieldBlocState<T, ExtraData> state = super.state;
final List<T> fieldBlocs = state.fieldBlocs;
return state.copyWith(
isValid: fieldBlocs.isEmpty
? false
: ffb.MultiFieldBloc.areFieldBlocsValid(fieldBlocs),
isValidating: fieldBlocs.isEmpty
? false
: ffb.MultiFieldBloc.areFieldBlocsValidating(fieldBlocs),
);
}
}
You can use now _ListFieldBloc
instead of the original ListFieldBloc
while an official fix is not released.
It works for me, but I don't know if it works for all use cases.