How can i use Listview.builder
with provider
? I trying to access the data from other widgets. By using Provider.of
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (BuildContext context, int index) {
final data = snapshot.data[index];
return Provider.value(
value: (_) => data,
child: const ReportWidget(),
);
},
);
class ReportWidget extends StatelessWidget {
const ReportWidget();
@override
Widget build(BuildContext context) {
final reportData = Provider.of<ReportModel>(context);
print(reportData);
return Card(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
],
),
);
}
}
It should be like this to get data from Provider:
final reportData = Provider.of<ReportModel>(context).listName;
You have to specify the data member or method to correctly access data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.