@@ -9,7 +9,7 @@ class EmployeeDataSource extends DataGridSource {
99
1010…..
1111
12- @override
12+ @override
1313 DataGridRowAdapter buildRow(DataGridRow row) {
1414 return DataGridRowAdapter(
1515 cells: row.getCells().map<Widget>((DataGridCell cell) {
@@ -29,46 +29,12 @@ class EmployeeDataSource extends DataGridSource {
2929 SizedBox(
3030 width: 40,
3131 child: Builder(builder: (context) {
32- int rowIndex = datagridRows.indexOf(row);
32+ datagridRows.indexOf(row);
3333 return IconButton(
3434 hoverColor: Colors.transparent,
3535 color: Colors.blue,
3636 icon: const Icon(Icons.expand_more),
37- onPressed: (() {
38- showDialog<String>(
39- context: context,
40- builder: (BuildContext context) => AlertDialog(
41- scrollable: true,
42- titleTextStyle: const TextStyle(
43- color: Colors.black,
44- fontWeight: FontWeight.bold,
45- fontSize: 16),
46- title: const Text('Personal Details'),
47- actions: [
48- TextButton(
49- onPressed: (() {
50- Navigator.pop(context);
51- }),
52- child: const Text('Close'))
53- ],
54- content: Container(
55- margin: const EdgeInsets.all(20),
56- child: Row(
57- children: [
58- const SizedBox(width: 20),
59- Text(
60- 'Employee address \n \n${employees[rowIndex].address}'),
61- const SizedBox(width: 20),
62- Text(
63- 'City \n \n${employees[rowIndex].city}'),
64- const SizedBox(width: 20),
65- Text(
66- 'Country \n \n${employees[rowIndex].country}'),
67- const SizedBox(width: 20),
68- ],
69- ),
70- )));
71- }),
37+ onPressed: () => _showDetailsDialog(context, row),
7238 );
7339 }),
7440 )
@@ -87,6 +53,41 @@ class EmployeeDataSource extends DataGridSource {
8753 );
8854 }).toList());
8955 }
56+
57+ void _showDetailsDialog(BuildContext context, DataGridRow row) {
58+ int rowIndex = datagridRows.indexOf(row);
59+ showDialog<String>(
60+ context: context,
61+ builder: (BuildContext context) => AlertDialog(
62+ scrollable: true,
63+ titleTextStyle: const TextStyle(
64+ color: Colors.black,
65+ fontWeight: FontWeight.bold,
66+ fontSize: 16,
67+ ),
68+ title: const Text('Personal Details'),
69+ actions: [
70+ TextButton(
71+ onPressed: () => Navigator.pop(context),
72+ child: const Text('Close'),
73+ ),
74+ ],
75+ content: Padding(
76+ padding: const EdgeInsets.all(20.0),
77+ child: Column(
78+ crossAxisAlignment: CrossAxisAlignment.start,
79+ children: [
80+ Text('Employee address: ${employees[rowIndex].address}'),
81+ const SizedBox(height: 10),
82+ Text('City: ${employees[rowIndex].city}'),
83+ const SizedBox(height: 10),
84+ Text('Country: ${employees[rowIndex].country}'),
85+ ],
86+ ),
87+ ),
88+ ),
89+ );
90+ }
9091}
9192```
9293
0 commit comments