Flutter-从数据库中获取记录并使用ListView Builder显示出来

数据保存在数据库中,根据表名称获取所有记录的列表,并在"ListView.builder"中显示的代码如下:

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]}'),
                ),
              );
              },
          );
        },
      ),
    );
  }
}

参考链接