List is not getting load on screen while navigating from one screen to another (FLUTTER LISTVIEW BUILDER)

Viewed 25
class NewListing extends HookConsumerWidget {
  NewListing({required this.catID});

  String catID;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final l10n = useL10n();
    final categoryByIDViewModel = ref.read(getCategoryByIDViewModelProvider);
    final categoriesByID = ref.watch(getCategoryByIDViewModelProvider
        .select((value) => value.categoryByIdList));

    final snap = useFuture(
      useMemoized(() {
        categoryByIDViewModel.page = 1;
        categoryByIDViewModel.category = catID;
        categoryByIDViewModel.limit = 20;
        return ref
            .read(loadingStateProvider)
            .whileLoading(categoryByIDViewModel.fetchCategoriesById);
      }, [categoriesByID?.toString()]),
    );
    return Container(
      decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage(Assets.images.loginBackground.path),
              fit: BoxFit.cover)),
      height: 25,
      child: ContainerWithLoading(
        child: snap.isWaiting || categoriesByID == null
            ? const SizedBox()
            : categoriesByID.when(success: (response) {
                if (response.data!.isEmpty) {
                  return Center(child: Text(l10n.noResult));
                }
                return RefreshIndicator(
                  onRefresh: () async =>
                      categoryByIDViewModel.fetchCategoriesById(),
                  child: ListView.builder(
                    scrollDirection: Axis.vertical,
                    primary: false,
                    shrinkWrap: true,
                    itemCount: response.data!.length,
                    physics: NeverScrollableScrollPhysics(),
                    itemBuilder: (_, index) {
                      return ProductList(categoryID: response.data![index]);
                    },
                  ),
                );
              }, failure: (e) {
                return Center(child: Text(l10n.fetchFailed));
              }),
      ),
    );
  }
}

I am creating a multi-paged app on flutter. When I am using the navigation in it, I am getting a black screen. so when we get data from get api i am building a list using that data but api is able to fetch the data but when entering screen where ui is being build it turns black after loading. Ihave tried building UI of list without api data then it gets build so I found that issue comes up at listview.builder as it is building up the list that by passing data to the screen where UI is being build . I am using MVVM architecture over here such that using view model i am fetching data using get API and it gets logged in the console so data is being fetched but listview is not building up the list that is required

0 Answers
Related