Skip to content

Instantly share code, notes, and snippets.

@rajajawahar
Last active May 9, 2018 02:06
Show Gist options
  • Save rajajawahar/cfdea08e532bf2a43eb8fb329b31ce5e to your computer and use it in GitHub Desktop.
Save rajajawahar/cfdea08e532bf2a43eb8fb329b31ce5e to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:sqflitedatabase/model/employee.dart';
import 'dart:async';
import 'package:sqflitedatabase/database/dbhelper.dart';
Future<List<Employee>> fetchEmployeesFromDatabase() async {
var dbHelper = DBHelper();
Future<List<Employee>> employees = dbHelper.getEmployees();
return employees;
}
class MyEmployeeList extends StatefulWidget {
@override
MyEmployeeListPageState createState() => new MyEmployeeListPageState();
}
class MyEmployeeListPageState extends State<MyEmployeeList> {
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(
title: new Text('Employee List'),
),
body: new Container(
padding: new EdgeInsets.all(16.0),
child: new FutureBuilder<List<Employee>>(
future: fetchEmployeesFromDatabase(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return new ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Text(snapshot.data[index].firstName,
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 18.0)),
new Text(snapshot.data[index].lastName,
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 14.0)),
new Divider()
]);
});
} else if (snapshot.data.length == 0) {
return new Text("No Data found");
}
return new Container(alignment: AlignmentDirectional.center,child: new CircularProgressIndicator(),);
},
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment