数据保存在数据库中,根据表名称获取所有记录的列表,并在"ListView.builder"中显示的代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
class _EmployeesListScreenState extends State<EmployeesListScreen> { var db = new DatabaseHelper(); // CALLS FUTURE @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('List Of Employees'), ), body: FutureBuilder<List>( future: db.getAllRecords("tabEmployee"), initialData: const [], builder: (context, snapshot) { return snapshot.hasData ? ListView.builder( itemCount: snapshot.data?.length, itemBuilder: (_, int position) { final item = snapshot.data?.elementAt(position); //get your item data here ... return Card(child: ListTile( title: Text('Employee Name: ${item?.row[1]}'), ), ); }, ); }, ), ); } } |