0

i am using cubit with freezd. i have an input text form field inside a bottom sheet, all thing is perfect, but once i clicked the input form field and typing any letter this exception occurs.

Another exception was thrown: Error: Could not find the correct Provider above this BlocSelector<HCubit, HState, HState> Widget

the text form field code is:

class TextInput extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    TextEditingController _textEditingController = TextEditingController();
    return BlocSelector<HCubit, HState, String?>(
        selector: (state) {
          return state.maybeMap(
              orElse: () {},
              inputTextValue: (val) =>
                  val.inputTextValue.input.fold((l) => l.msg, (r) => null));
        },
        builder: (context, state) {
          return TextFormField(
              textAlign: TextAlign.start,
              onChanged: (String value) => context
                  .read<HState>()
                  .maybeMap(inputTextValue: (value) => value, orElse: () {}),
              validator: (String? validator) => context
                  .read<HState>()
                  .maybeWhen(
                      orElse: () {},
                      inputTextValue: (val) =>
                          val.input.fold((l) => l.msg, (r) => null)),
              );
        },
      ),
    );
  }
}

material app code:

class AppWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Sizer(
      builder: (context, orientation, deviceType) {
        return MaterialApp(
          BlocProvider<HCubit>(
            lazy: false,
            create: (context) => HCubit(),
            child: const
             HomePage(),
          ),
        );
      },
    );
  }
}

bloc code is:

class HCubit extends Cubit<HState> {
  HCubit() : super(const HState.initial());
  void addNewNoteButton({required bool isClicked}) =>
      emit(HState.isClicked(isClicked: isClicked));

  void textInputNote({required String textNote}) =>
      emit(HState.inputTextValue(inputTextValue: Note(textInput: textNote)));
}

state code is:

abstract class HState with _$HState {
  const factory HState.initial() = _Initial;
  const factory HState.inputTextValue({required Note inputTextValue})=InputTextValue;
  const factory HState.isClicked({required bool isClicked})=IsClicked;
}

1 Answers1

0

In your material app code has a syntax error it should be like that:

class AppWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Sizer(
      builder: (context, orientation, deviceType) {
        return MaterialApp(
          home: BlocProvider<HCubit>(
            lazy: false,
            create: (context) => HCubit(),
            child: const
             HomePage(),
          ),
        );
      },
    );
  }
}
Mohamed Kamel
  • 841
  • 10
  • 15