cannot access members of tuple in future builder in flutter


I have a Tuple which has two members: List<DeliveryAddressModel> and ApiResponseCode. The code is as follows:

  Future<Tuple2<List<DeliveryAddressModel>, ApiResponseCode>> getAddressList() async {
    int retry  0;
    List<DeliveryAddressModel> deliveryAddressList  [];
    while (retry++ < 2) {
      try {
            await CoreRepo.instance.getCoreClient().getDeliveryAddresses();

        for (int i  0; i < deliveryAddressList.length; i++) {
          print("inside core repo: ${deliveryAddressList[i].addressTitle}");
        return Tuple2(deliveryAddressList, ApiResponseCode.SUCCESS);
      } catch (e) {
    return Tuple2(deliveryAddressList, ApiResponseCode.SERVER_ERROR);

Now inside some other page I need to show the data, more specifically List<DeliveryAddressModel>.

So this is what I tried:

  body: FutureBuilder(
    future: CoreRepo.instance.getAddressList(),
    builder: (context, snapshot) {
      if (  null) {
        return LoadingWidget(
          status: "Loading your delivery addresses",
      if (  ApiResponseCode.FAILED) { > ERROR 1
        return Text("Failed");
      return RefreshIndicator(
        child: buildFeed(, > ERROR 1
        onRefresh: () > refreshList(context),


The property 'item2' can't be unconditionally accessed because the receiver can be 'null'.

Try making the access conditional (using '?.') or adding a null check to the target ('!').

This comes straight from the documentation of tuple:

const t Tuple2(‘a’, 10);

print(t.item1); // prints ‘a’ print(t.item2); // prints ’10’

For more info: core_repo, core_client, delivery_list_page


Because the snapshot data itself could be null you should safely access its value

Also you need modify future builder

FutureBuilder<Tuple2<List<DeliveryAddressModel>, ApiResponseCode>>>

because future builder can not infer the data type you should provide it your self

Answered By – Hosam Hasan

Leave a Comment