-
Notifications
You must be signed in to change notification settings - Fork 20
/
employeelist.dart
104 lines (98 loc) · 3.48 KB
/
employeelist.dart
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
///
/// Copyright (C) 2018 Andrious Solutions
///
/// This program is free software; you can redistribute it and/or
/// modify it under the terms of the GNU General Public License
/// as published by the Free Software Foundation; either version 3
/// of the License, or any later version.
///
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
/// Created 24 Nov 2018
///
import 'package:flutter/material.dart';
import 'employee.dart' show Employee;
import 'employeedetail.dart';
class MyEmployeeList extends StatefulWidget {
MyEmployeeList({Key key}) : super(key: key);
final MyEmployeeListPageState state = MyEmployeeListPageState();
@override
MyEmployeeListPageState createState() => state;
}
class MyEmployeeListPageState extends State<MyEmployeeList> {
Employee db;
@override
void initState() {
super.initState();
db = Employee();
// db.init();
}
@override
void dispose(){
db.disposed();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Employee List'),
),
body: Container(
padding: EdgeInsets.all(16.0),
child: FutureBuilder<List<Map<String, dynamic>>>(
future: db.getEmployees(),
builder: (context, snapshot) {
if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index) {
return InkWell(
onTap: Feedback.wrapForTap(
() => Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) => MyEmployee(
employee: snapshot.data[index]))),
context),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(snapshot.data[index]['firstname'],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0)),
Text(snapshot.data[index]['lastname'],
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0)),
Divider()
]));
});
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return Container(
alignment: AlignmentDirectional.center,
child: CircularProgressIndicator(),
);
},
),
),
floatingActionButton: FloatingActionButton(
child: Icon(Icons.add),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
builder: (BuildContext context) =>
MyEmployee(employee: db.emptyRec())));
}),
);
}
}