📙 CUBIT_USAGE.md
This document provides examples of how to use various Cubits
available in the reusable_editor
package.
✅ FieldCubit
Generic Cubit for managing form fields with validation.
final nameCubit = FieldCubit<String>(
: 'Default Name',
initialValue: RequiredStringValidator(),
validator
);
.update('John Doe');
nameCubitfinal error = nameCubit.validate(); // returns null if valid
✅ ToggleCubit
Specialized Cubit for boolean toggle fields.
final toggleCubit = ToggleCubit(initialValue: false);
.update(true); toggleCubit
✅ DateTimeCubit
Cubit for managing date selection.
final dateCubit = DateTimeCubit(initialValue: DateTime.now());
.update(DateTime(2025, 7, 1)); dateCubit
✅ ImageCrudCubit
Cubit to handle image picking, uploading, and validation.
final imageCubit = ImageCrudCubit();
await imageCubit.pickImage();
✅ SelectionCubit
Generic selection Cubit for enum or any type of selection.
enum Gender { male, female, other }
final genderSelectionCubit = SelectionCubit<Gender>(initialValue: Gender.male);
.update(Gender.female); genderSelectionCubit
✅ SwitchCubit
Cubit to manage simple boolean switch state.
final switchCubit = SwitchCubit(initialValue: false);
.update(true); switchCubit
✅ TextFieldCubit
Cubit specialized for text field validation and management.
final textFieldCubit = TextFieldCubit(
: '',
initialValue: RequiredStringValidator(),
validator
);
.update('Hello World'); textFieldCubit