0

I got a page in flutter than contains future builder, and the result of it displayed in list view builder. When I get small amount of data, flutter display the data without any problem. But when I get large amount of data, it display nothing.

What I get from this problem is when I get large amount of data, future builder hasn't finished get the data before the page is shown.

How can I make the page wait for the future finished to get the data before the page is shown?

Thanks

FutureBuilder<List<SalesTable>>(
            future: SelectSalesTable.getSalesTable(widget.kodesales,
                daterange1.format(widget.tgl1), daterange2.format(widget.tgl2)),
            builder: (context, snapshot) {
              if (snapshot.connectionState == ConnectionState.none) {
                return new Text('No Data..!!');
              } else if (snapshot.connectionState == ConnectionState.waiting) {
                return new Center(child: CircularProgressIndicator());
              } else {
                if (snapshot.hasData) {
                  List<SalesTable> data = snapshot.data;
                  return Container(
                      child: Column(
                    children: [
                      ListView.builder(
                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(),
                        itemBuilder: (context, index) {
                          return Column(
                            children: [
                              Padding(
                                padding: const EdgeInsets.fromLTRB(5, 5, 5, 5),
                                child: Card(
                                  shadowColor: Colors.grey,
                                  shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(10.0),
                                  ),
                                  elevation: 10,
                                  child: Padding(
                                    padding:
                                        const EdgeInsets.fromLTRB(5, 10, 5, 10),
                                    child: ListTile(
                                      title: Text(
                                          data[index].name +
                                              ' | ' +
                                              data[index].Category,
                                          style: TextStyle(
                                              fontSize: 20,
                                              fontWeight: FontWeight.bold)),
                                      subtitle: Column(
                                        children: <Widget>[
                                          Row(
                                            children: <Widget>[
                                              Expanded(
                                                child: Text(
                                                    'Date : ' +
                                                        dateformat3.format(
                                                            data[index]
                                                                .date1),
                                                    style: TextStyle(
                                                        fontWeight:
                                                            FontWeight.bold)),
                                              )
                                            ],
                                          ),
                                        ],
                                      ),
                                      onTap: () {},
                                    ),
                                  ),
                                ),
                              ),
                            ],
                          );
                        },
                        itemCount: data.length,
                      ),
                    ],
                  ));
                } else if (snapshot.hasError) {
                  return Text("${snapshot.error}");
                }
              }

              return Center(child: CircularProgressIndicator());
            },
          )
Heri Kwok
  • 1
  • 2
  • Please share code snippets. From what you say it seems you didn't check snapshot.hasData or snapshot.connectionState – p2kr Jun 09 '21 at 06:42
  • thanks for posting an answer, I've edited my previous post with code. – Heri Kwok Jun 10 '21 at 05:32
  • the problem is when I get lot of data from database to snapshot, it doesn't appear. But when I get less data it appears correctly. I think the future hasn't finished to fetch data before the page displayed. Can you help me to solve this.. thanks.. – Heri Kwok Jun 10 '21 at 05:34
  • try removing `physics: NeverScrollableScrollPhysics(),`. Look more about `shrinkWrap` property. A screenshot of expected result and actual result will be appreciated – p2kr Jun 10 '21 at 10:10
  • Sorry I have already got the problem. It's my web services problem. I got the problem when I run debugging using breakpoint in VSC. When the service retrieve data from table, it catches error and I trace it's from my grand total field. I declared the field with int instead of double. And in the other hand, it's a null total create an error too.. Thank you for responding my question.. – Heri Kwok Jun 11 '21 at 07:13
  • Please close the question then. – p2kr Jun 11 '21 at 08:32
  • hmm.. sorry I'm new here, how to close the question..?? – Heri Kwok Jun 15 '21 at 13:29

0 Answers0