Flutter error: The following NoSuchMethodError was thrown building Flutter error: The following NoSuchMethodError was thrown building dart dart

Flutter error: The following NoSuchMethodError was thrown building


It seems that your provider takes a little time to fetch the Store List so the stores is null for a while. You can display a progress indicator while the stores is null then display the data afterwards

class _DataListState extends State<DataList> {  @override  Widget build(BuildContext context) {    final stores = Provider.of<List<Store>>(context);    // stores.forEach((d) {    //   print(d.name);    // });    return stores == null             ? Center(child: CircularProgressIndicator())            : ListView.builder(      itemCount: stores.length,      itemBuilder: (context, index) {        return StoreTile(store: stores[index]);      },    );  }}


Your provider is getting some time to fetch the data, use CircularProgressIndicator till then

 stores.length >0 ? ListView.builder(        itemCount: stores.length,        itemBuilder: (context, index) {          return StoreTile(store: stores[index]);        },      ) : CircularProgressIndicator();