@@ -40,7 +40,7 @@ class SourcedPagingBloc<T>
4040 _init ();
4141 }
4242
43- SourcedPagingBloc .simple (
43+ SourcedPagingBloc .item (
4444 {required this .cubit,
4545 this .sources,
4646 required Future <List <T >?> Function (
@@ -53,6 +53,20 @@ class SourcedPagingBloc<T>
5353 _init ();
5454 }
5555
56+ SourcedPagingBloc .source ({
57+ required this .cubit,
58+ required String source,
59+ required Future <List <T >?> Function (
60+ SourceService service, int offset, int limit)
61+ fetch,
62+ this .pageSize = 50 ,
63+ }) : sources = [source],
64+ useDates = false ,
65+ _fetch = _buildDatedFetchSource (fetch),
66+ super (const SourcedPagingInitial ()) {
67+ _init ();
68+ }
69+
5670 void _init () {
5771 on < SourcedPagingFetched > (_onFetched);
5872 on < SourcedPagingRefresh > ((event, emit) {
@@ -62,8 +76,11 @@ class SourcedPagingBloc<T>
6276 on < SourcedPagingRemoved > ((event, emit) {
6377 final state = this .state;
6478 if (state is SourcedPagingSuccess <T >) {
65- final items =
66- state.dates.map ((e) => e.where ((i) => i != event.item).toList ());
79+ final items = state.dates.map ((e) => e
80+ .where ((i) =>
81+ i.model == event.item &&
82+ (event.source == null || (i.source == event.source)))
83+ .toList ());
6784 emit (SourcedPagingSuccess (
6885 currentPageKey: state.currentPageKey,
6986 dates: items.toList (),
@@ -150,7 +167,9 @@ class SourcedPagingBloc<T>
150167 add (SourcedPagingFetched ());
151168 }
152169
153- void remove (SourcedModel <T > item) => add (SourcedPagingRemoved (item));
170+ void remove (SourcedModel <T > item) =>
171+ add (SourcedPagingRemoved (item.model, item.source));
172+ void removeSourced (T item) => add (SourcedPagingRemoved (item));
154173}
155174
156175_buildDatedFetch <T >(
@@ -162,3 +181,11 @@ _buildDatedFetch<T>(
162181 final items = await fetch (source, service, offset, limit);
163182 return items;
164183 };
184+ _buildDatedFetchSource <T >(
185+ Future <List <T >?> Function (SourceService service, int offset, int limit)
186+ fetch) =>
187+ (String source, SourceService service, int offset, int limit,
188+ int date) async {
189+ final items = await fetch (service, offset, limit);
190+ return items;
191+ };
0 commit comments