Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/src/form_group_cubit/form_group_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,14 @@ class FormGroupCubit extends Cubit<FormGroupState> with Disposable {

/// Adds a subform to the current form.
/// If [form] was already added as a subform this is a noop.
/// If [form] is closed this will throw a [StateError].
void addSubform(FormGroupCubit form) {
if (form.isClosed) {
throw StateError(
'Cannot add a closed form',
);
}

emit(
FormGroupState(
wasModified: state.wasModified,
Expand Down
14 changes: 14 additions & 0 deletions test/src/form_group_cubit/form_group_cubit_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,20 @@ void main() {
},
expect: () => <dynamic>[],
);

blocTest<FormGroupCubit, FormGroupState>(
'throws if form is closed',
build: () => form,
setUp: () => subform.close(),
act: (cubit) {
cubit.addSubform(subform);
},
errors: () => [
predicate(
(e) => e is StateError && e.message == 'Cannot add a closed form',
),
],
);
});

group('validateAll', () {
Expand Down
Loading