forked from md-siam/widget_of_the_day
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_table.dart
112 lines (107 loc) · 3.67 KB
/
data_table.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
import 'package:flutter/material.dart';
class MyDataTable extends StatefulWidget {
const MyDataTable({Key? key}) : super(key: key);
@override
State<MyDataTable> createState() => _MyDataTableState();
}
class _MyDataTableState extends State<MyDataTable> {
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return Scaffold(
appBar: AppBar(title: const Text('Data Table')),
body: SingleChildScrollView(
child: DataTable(
//border: TableBorder.all(),
columnSpacing: width * 0.07,
onSelectAll: (b) {},
sortColumnIndex: 0,
sortAscending: false,
columns: <DataColumn>[
DataColumn(
label: const Text("First Name"),
numeric: false,
onSort: (i, b) {
setState(() {
names.sort((a, b) => a.firstName.compareTo(b.firstName));
b = true;
});
},
tooltip: "To display first name of the Name",
),
DataColumn(
label: const Text("Last Name"),
numeric: false,
onSort: (i, b) {
setState(() {
names.sort((a, b) => a.lastName.compareTo(b.lastName));
});
},
tooltip: "To display last name of the Name",
),
DataColumn(
label: const Text("Age"),
numeric: false,
onSort: (i, b) {
setState(() {
names.sort((a, b) => a.age.compareTo(b.age));
});
},
tooltip: "To display age",
),
],
rows: names
.map(
(name) => DataRow(
onSelectChanged: (b) {},
cells: [
DataCell(
Text(name.firstName),
showEditIcon: false,
placeholder: false,
),
DataCell(
Text(name.lastName),
showEditIcon: false,
placeholder: false,
),
DataCell(
Text(name.age.toString()),
showEditIcon: false,
placeholder: false,
),
],
),
)
.toList(),
),
),
);
}
}
class Name {
String firstName;
String lastName;
int age;
Name({required this.firstName, required this.lastName, required this.age});
}
var names = <Name>[
Name(firstName: "Murshed", lastName: "Islam", age: 27),
Name(firstName: "Ibn", lastName: "Sina", age: 27),
Name(firstName: "Amil", lastName: "Hossain", age: 28),
Name(firstName: "Md.", lastName: "Siam", age: 27),
Name(firstName: "Ashik", lastName: "Mahmud", age: 27),
Name(firstName: "Billal", lastName: "Hossain", age: 25),
Name(firstName: "Samiul", lastName: "Kaiser", age: 35),
Name(firstName: "Kamal", lastName: "Hossain", age: 31),
Name(firstName: "Sabbir", lastName: "Ali", age: 20),
Name(firstName: "Akiq", lastName: "Islam", age: 27),
Name(firstName: "Sabrina", lastName: "Ilieas", age: 27),
Name(firstName: "Kiamot", lastName: "Ali", age: 28),
Name(firstName: "Kowsar", lastName: "Habbab", age: 27),
Name(firstName: "Kifaet", lastName: "Kibria", age: 27),
Name(firstName: "Munna", lastName: "Hossain", age: 25),
Name(firstName: "Musharaf", lastName: "Ali", age: 35),
Name(firstName: "Kamal", lastName: "Hossain", age: 31),
Name(firstName: "Sammi", lastName: "Istiak", age: 20),
];