Skip to content

Data loading does not work. #135

@Patrick386

Description

@Patrick386

I combined Riverpod to process the screen and data.
Currently, the package only supports Stream.
I cannot display the Loading state of the data on the screen.
Is it possible to support Future? Or is there a way to know the Data Loading state?

Note that I am not using 'StreamBuilder'.
Even after changing to 'StreamNotifier', the issue remains the same.

@riverpod
class ItemPagingAlgoliaController extends _$ItemPagingAlgoliaController {
  late final HitsSearcher hitsSearcher;

  @override
  FutureOr<AlgoliaDataState<ItemData>?> build({bool published = true}) {

    state = AsyncValue.data(AlgoliaDataState<ItemData>( hitsPerPage: 20));

    hitsSearcher = HitsSearcher(
      applicationID: Env.algoliaApplicationID,
      apiKey: Env.algoliaSearchOnlyKey,
      indexName: AlgoliaCredentials.itemIndex,
    );

    hitsSearcher.responses.listen(_fetchDataUpdate); // ** Stream listen
    return state.value;
  }

  void _fetchDataUpdate(){
          ...
         update((s)=> s.copyWidth(items: items));
      }
}

UI:

class _DataListScreen extends ConsumerWidget {
  const _DataListScreen({super.key});

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    var sts = ref.watch(itemPagingAlgoliaControllerProvider(published: true));

    return sts.when(
        data: (dataState) {
          return _DataTableScreen(items: dataState?.items ??[]);
        },
        error: (s, t) => Text('Error'),
        loading: () => const LoadingData()); //*** Loading not working..
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions