How do I make my list display? (Dart & Flutter)

Issue

HIIII! I have this problem where I need to display items, but I cant. I don’t know where i should put the FutureBuilder. It’s supposed to display thisenter image description here

  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Column(
            children: [
              Column(
                children: [
                  HomeAppBar(),
                  PointShopInfo(),
                  Text(
                    "Items",
                    style: TextStyle(
                      fontFamily: 'Inter-bold',
                      fontSize: 23,
                    ),
                  ),
                ],
              ),
              FutureBuilder(
                future: _getRedeemShop(),
                builder: (BuildContext context, AsyncSnapshot snapshot3) {
                  if (snapshot3.data == null) {
                    return Center(
                      child: Text(
                        "Nothing to see here...",
                        style: TextStyle(
                          color: Color.fromARGB(255, 150, 150, 150),
                          fontSize: 16,
                          fontFamily: 'Inter',
                        ),
                      ),
                    );
                  } else {
                    return ListView.builder(
                      itemCount: snapshot3.data.length,
                      itemBuilder: (BuildContext context, int index) {
                        PointShopData data = snapshot3.data[index];
                        return Card(
                          color: Colors.white,
                          margin:
                              EdgeInsets.symmetric(horizontal: 10, vertical: 5),
                          child: ListTile(
                            title: Text(
                              snapshot3.data[index].points_name,
                              style: TextStyle(
                                fontFamily: 'Inter-bold',
                                fontSize: 18,
                              ),
                            ),
                            subtitle: Text(
                              snapshot3.data[index].points.toString(),
                              style: TextStyle(
                                fontFamily: 'Inter-semibold',
                                fontSize: 12,
                              ),
                            ),
                          ),
                        );
                      },
                    );
                  }
                },
              ),
            ],
          ),
        ],
      ),
    );
  }

I’ve tried putting it in the same column as other elements and it still looks like thisenter image description here

Solution

try this

 if (snapshot3.connectionState == ConnectionState.done && snapshot3.data == null) {
  return Center(
    child: Text(
      "Nothing to see here...",
      style: TextStyle(
        color: Color.fromARGB(255, 150, 150, 150),
        fontSize: 16,
        fontFamily: 'Inter',
      ),
    ),
  );
}

for checking if the data is null and successfully connect so show the message otherwise you’ll show your list

if this not working what your debug say ?

Answered By – Ali Nabel

Answer Checked By – Gilberto Lyons (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *