此问题可能由多种原因引起,需要进一步排查。下面是可能的解决方案:
以下是示例代码,可能会有所帮助:
// Bloc state
class ExampleState {
final bool isUpdating;
ExampleState({this.isUpdating});
ExampleState copyWith({bool isUpdating}) {
return ExampleState(
isUpdating: isUpdating ?? this.isUpdating,
);
}
}
// Bloc events
abstract class ExampleEvent {}
class UpdateExampleEvent extends ExampleEvent {
final bool isUpdating;
UpdateExampleEvent(this.isUpdating);
}
// Bloc logic
class ExampleBloc extends Bloc {
ExampleBloc() : super(ExampleState(isUpdating: false));
@override
Stream mapEventToState(ExampleEvent event) async* {
if (event is UpdateExampleEvent) {
yield state.copyWith(isUpdating: event.isUpdating);
}
}
}
// Bloc builder
BlocBuilder(
builder: (context, state) {
return Text('Is updating: ${state.isUpdating}');
},
)
上一篇:Bloc流如何被填充?