抛出另一个异常:错误:无法<HState>在此 BlocSelector<HCubit、HState、HState > 小部件上方找到正确的提供程序



我正在使用cubit with freeze。我在底部表单中有一个输入文本表单字段,一切都很完美,但是一旦我单击输入表单字段并键入任何字母,就会出现异常。

抛出另一个异常:错误:无法在此blocselectorhcubit, HState, HState>小部件

文本表单字段代码为:

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)),
);
},
),
);
}
}

材料应用程序代码:

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(),
),
);
},
);
}
}

分组代码为:

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)));
}

状态代码为:

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;
}

在你的材料应用程序代码中有一个语法错误,它应该是这样的:

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(),
),
);
},
);
}
}

相关内容

  • 没有找到相关文章

最新更新