I'm working on a Flutter project and using Sqflite database. I've managed to save data in db. Now I am trying to get list of all records from database based on table name and display them in "ListView.builder".
database_helper.dart
Future<List> getAllRecords(String dbTable) async {
var dbClient = await db;
var result = await dbClient.rawQuery("SELECT * FROM $dbTable");
return result.toList();
}
employees_list.dart
import 'package:flutter/material.dart';
import 'package:flutter_with_db_single_helper/helpers/database_helper.dart';
var db = new DatabaseHelper();
Future<List> _users = db.getAllRecords("tabEmployee"); // CALLS FUTURE
class EmployeesListScreen extends StatefulWidget {
@override
_EmployeesListScreenState createState() => _EmployeesListScreenState();
}
class _EmployeesListScreenState extends State<EmployeesListScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('List Of Employees'),
),
body: ListView.builder(
// itemCount: _users.length,
itemBuilder: (_, int position) {
return Card(
child: ListTile(
title:
Text("Employee Name: "), // EMPLOYEE NAME TO BE DISPLAYED HERE
),
);
},
),
);
}
}
Where did I go wrong? What can I do to display all my db table records in list?