bloc

Triggering initial event in BLoC

帅比萌擦擦* 提交于 2020-12-29 13:12:38
问题 example_states: abstract class ExampleState extends Equatable { const ExampleState(); } class LoadingState extends ExampleState { // } class LoadedState extends ExampleState { // } class FailedState extends ExampleState { // } example_events: abstract class ExampleEvent extends Equatable { // } class SubscribeEvent extends ExampleEvent { // } class UnsubscribeEvent extends ExampleEvent { // } class FetchEvent extends ExampleEvent { // } example_bloc: class ExampleBloc extends Bloc

Dart Provider: not available at the immediate child

旧巷老猫 提交于 2020-12-15 05:01:51
问题 @override Widget build(BuildContext context) { return BlocProvider<HomeBloc>( create: (context) { return HomeBloc(homeRepo: HomeRepository()); }, child: BlocProvider.of<HomeBloc>(context).state is HomeStateLoading ? CircularProgressIndicator() : Container()); } I am confused with the error: BlocProvider.of() called with a context that does not contain a Bloc of type HomeBloc. No ancestor could be found starting from the context that was passed to BlocProvider.of<HomeBloc>(). Didn't I just

Flutter: Read the Stream data of a BloC state and re-render the UI if it changes

点点圈 提交于 2020-12-13 03:33:00
问题 I have a problem with using the BloC pattern in combination with showing a download process using Dio. Can anybody tell me, how to get the onUploadProgress from dio into a bloc state and display it when the progress inside the state updates? At the moment I have the UI, the BloC and an API class. I need to pass my bloc into the API call to download a file and then add an extra event like so: onReceiveProgress: (int received, int total) => { bloc.add(DownloadingImages((received / total) * 100)

Flutter BLoC mapEventToState gets called only the first time for an event and not called each next time that event is fired

孤人 提交于 2020-12-12 11:06:26
问题 I have Courses and Tasks . Each Course has many Tasks . That is why I am using different screens in the app to show a list of courses and after a tap on a course, I am navigating to the next screen - a list of tasks. Here is my onTap method of the list of courses: onTap: () { TasksPageLoadedEvent pageLoadedEvent = TasksPageLoadedEvent( courseId: state.courses[index].id, truckNumber: this.truckNumber, ); serviceLocator<TaskBloc>().add(pageLoadedEvent); Routes.sailor( Routes.taskScreen, params:

Flutter BLoC mapEventToState gets called only the first time for an event and not called each next time that event is fired

假装没事ソ 提交于 2020-12-12 11:06:16
问题 I have Courses and Tasks . Each Course has many Tasks . That is why I am using different screens in the app to show a list of courses and after a tap on a course, I am navigating to the next screen - a list of tasks. Here is my onTap method of the list of courses: onTap: () { TasksPageLoadedEvent pageLoadedEvent = TasksPageLoadedEvent( courseId: state.courses[index].id, truckNumber: this.truckNumber, ); serviceLocator<TaskBloc>().add(pageLoadedEvent); Routes.sailor( Routes.taskScreen, params: