Click here to Skip to main content
15,894,539 members

Comments by Digiyang (Top 4 by date)

Digiyang 8-Aug-22 4:23am View    
I solved my problem actually :D
I did a bloc for my StripePayment with two separated events and I will post the answer later.
Digiyang 8-Aug-22 3:05am View    
Well, I'm trying to pass extra directly in the DonateScreen.
To access the DonateScreen, I have to press a button in a conversation, but I don't want to pass the extra value as a parameter.
For me it doesn't make much sense, as the extra price has to be chosen on the DonateScreen.

Here an example: https://imgur.com/IRsjRMB

_handlePressDonate(Item? item) {
    if (item != null) {
      BlocProvider.of<ItemBloc>(context).add(LoadItem(item.id));
      BlocProvider.of<ProfileBloc>(context).add(LoadProfile(item.userId));
      context.router.push(
        DonateRoute(
            itemId: item.id, conversationId: widget.conversationId),
      );
    }
  }
Digiyang 5-Aug-22 3:31am View    
Hi I already solved my issue thank you :D
Should I post it here for others ?
Digiyang 3-Aug-22 5:27am View    
Thank you for your answer! I also think the problem is coming from there, so this is what I did.
Future<List<Item>> fetchNgoItems(int ngoId, int startIndex) async {
    final http.Response response =
        await _httpClient.get("/ngo/$ngoId/item?page=$startIndex&size=$maxItemsPerPage");
    print(response.body);
    return jsonDecode(utf8.decode(response.bodyBytes))['content']
        .map<Item>((json) => Item.fromJson(json))
        .toList();
  }

so I included the index as a parameter in the bloc_event, initialised to 0 at the first call of the bloc and then incremented it.
try {
      if (state.status == ItemsStatus.initial) {
        final items = await backendAPI.fetchNgoItems(event.ngoId, event.index);
        return emit(state.copyWith(
          status: ItemsStatus.success,
          ngoItems: items,
          hasReachedMax: false,
        ));
      }
      final items = await backendAPI.fetchNgoItems(event.ngoId, event.index);
      emit(items.isEmpty
          ? state.copyWith(hasReachedMax: true)
          : state.copyWith(
              status: ItemsStatus.success,
              ngoItems: List.of(state.ngoItems)..addAll(items),
              hasReachedMax: false,
            ));
    }
Builder(builder: (context) {
        return BlocBuilder<NgoItemListBloc, NgoItemListState>(
          bloc: bloc
            ..add(
              LoadNgoItemList(ngo.id, pageIndex),
            ),


void _onScroll() {
    if (_isBottom) {
      context.read<NgoItemListBloc>().add(LoadNgoItemList(ngo.id, pageIndex += 1));
    }
  }


I should get:

{"content":[],"pageable":{"sort":{"empty":true,"sorted":false,"unsorted":true},**"offset":70**,**"pageNumber":7**,"pageSize":10,"paged":true,"unpaged":false},"totalPages":7,"totalElements":63,"last":true,"size":10,"number":7,"sort":{"empty":true,"sorted":false,"unsorted":true},"numberOfElements":0,"first":false,"empty":true}

but instead, I'm getting:
flutter: {"content":[],"pageable":{"sort":{"empty":true,"sorted":false,"unsorted":true},**"offset":150**,**"pageNumber":15,**"pageSize":10,"paged":true,"unpaged":false},"totalPages":7,"totalElements":63,"last":true,"size":10,"number":15,"sort":{"empty":true,"sorted":false,"unsorted":true},"numberOfElements":0,"first":false,"empty":true}


any idea what I'm doing wrong ?