forked from qwertypool/flutter-code-snippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paginatedDataTable.dart
121 lines (111 loc) · 3.92 KB
/
paginatedDataTable.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Sample Taken From One Of My Code//
import 'package:dash_admin_dashboard/Dashboard/MenuItems/addFeature.dart';
import 'package:dash_admin_dashboard/Dashboard/MenuItems/components/headingTextWidget.dart';
import 'package:dash_admin_dashboard/Dashboard/MenuItems/components/tableHeader.dart';
import 'package:dash_admin_dashboard/Dashboard/MenuItems/drawer.dart';
import 'package:dash_admin_dashboard/SignUp/Components/appbar.dart';
import 'package:dash_admin_dashboard/models/AdminModel/adminResponseModel.dart';
import 'package:dash_admin_dashboard/models/featureModel.dart';
import 'package:dash_admin_dashboard/service/networkHandler2.dart';
import 'package:flutter/material.dart';
class FeaturesTable extends StatefulWidget {
const FeaturesTable({Key key}) : super(key: key);
@override
_FeaturesTableState createState() => _FeaturesTableState();
}
class _FeaturesTableState extends State<FeaturesTable> {
Map<String, dynamic> resp;
bool circular = true;
NetworkHandler networkHandler = NetworkHandler();
FeatureModel featuremodel = FeatureModel();
AdminResponseModel adminResponse = AdminResponseModel();
String text;
@override
void initState() {
super.initState();
fetchData();
}
void fetchData() async {
var response = await networkHandler.get('feature?limit=100&page=1');
setState(() {
featuremodel = FeatureModel.fromJson(response);
circular = false;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: BuildAppbar(
isloggedIn: true,
),
body: Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: Row(
children: [
SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height ,
child: BuildDrawer()),
),
SizedBox(width: 10,),
Expanded(
child: circular
? Center(
child: CircularProgressIndicator(),
)
: ListView(
padding: const EdgeInsets.all(16),
children: [
PaginatedDataTable(
header: TableHeader(
headerText: 'Features Details',
page: AddFeature(),
header: 'Feature'),
rowsPerPage: 10,
columns: [
DataColumn(label: HeadingTextWidget(text: 'Name')),
DataColumn(label: HeadingTextWidget(text: 'Active')),
DataColumn(label: HeadingTextWidget(text: 'Key')),
DataColumn(label: HeadingTextWidget(text: 'Actions')),
],
source: _DataSource(context, featuremodel),
),
],
),
),
],
),
),
);
}
}
class _DataSource extends DataTableSource {
_DataSource(this.context, this.featuremodel);
final BuildContext context;
FeatureModel featuremodel;
@override
DataRow getRow(int index) {
return DataRow.byIndex(
index: index,
cells: [
DataCell(Text(featuremodel.results[index].name.toString(),)),
DataCell(Text(featuremodel.results[index].active.toString(),)),
DataCell(Text(featuremodel.results[index].key.toString(),)),
DataCell(Row(
children: [
IconButton(onPressed: () {}, icon: Icon(Icons.edit)),
SizedBox(width: 8,),
IconButton(onPressed: () {}, icon: Icon(Icons.delete)),
],
)),
],
);
}
@override
int get rowCount => featuremodel.totalResults;
@override
bool get isRowCountApproximate => false;
@override
int get selectedRowCount => 0;
}