DiscoverModule/lib/ui_screen/add_event/add_hcp.dart

200 lines
5.8 KiB
Dart
Raw Permalink Normal View History

2024-05-20 10:29:02 +00:00
import 'package:flutter/material.dart';
class Addhcp extends StatefulWidget {
const Addhcp({super.key});
@override
State<Addhcp> createState() => _AddhcpState();
}
class _AddhcpState extends State<Addhcp> {
late _DataSource _dataSource; // Instance variable for _DataSource
@override
void initState() {
super.initState();
print("hii_initState");
_dataSource = _DataSource(context); // Initialize _DataSource
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
padding: const EdgeInsets.all(3),
children: [
PaginatedDataTable(
header: const Text(
'HCP RANKING',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18.0,
fontStyle: FontStyle.normal),
),
showFirstLastButtons: true,
showEmptyRows: false,
showCheckboxColumn: true,
rowsPerPage: 5,
columns: const [
DataColumn(
label: Text('Name',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Tier',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Rank',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Score',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Event',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Affliations',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Publications',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Trails',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
],
source: _dataSource,
),
],
),
floatingActionButton: Visibility(
visible: true,
child: FloatingActionButton(
onPressed: () {
Navigator.pop(context);
},
child: Icon(Icons.add),
),
),
);
}
}
class _Row {
_Row(this.identifier, this.valueA, this.valueC, this.valueD, this.valueE,
this.valueF, this.valueG, this.valueH, this.valueI);
final int identifier;
final String valueA;
final String valueC;
final String valueD;
final String valueE;
final String valueF;
final String valueG;
final String valueH;
final String valueI;
bool selected = false;
}
class _DataSource extends DataTableSource {
final BuildContext context;
late List<_Row> _rows;
// late List<int> _selectedRowsIndexes = []; // List to track selected rows
final List<String> _selectedRowIds = [];
_DataSource(this.context) {
_rows = <_Row>[
for (int i = 0; i < 20; i++)
_Row(i, 'pooja', 'Tier1', '1', '0', '0', '0', '0', '0'),
];
//}
}
List<String> getSelectedRowIds() {
return _selectedRowIds; // Return a copy to prevent direct modification
}
int _selectedCount = 0;
@override
DataRow? getRow(int index) {
assert(index >= 0);
if (index >= _rows.length) return null;
final row = _rows[index];
return DataRow.byIndex(
index: index,
selected: row.selected,
onSelectChanged: (value) {
if (row.selected != value) {
// _selectedCount += value! ? 1 : -1;
// assert(_selectedCount >= 0);
row.selected = value!;
if (value) {
print("Selected");
_selectedRowIds.add(row.valueA); // Add the row ID to the list
print("Selected_selectedRowIds :$_selectedRowIds");
} else {
_selectedRowIds
.remove(row.valueA); // Remove the row ID from the list
}
notifyListeners();
print("Selectedddd_is $value");
print("Selectedddd_value ${row.valueA}");
}
},
cells: [
DataCell(
Text(row.valueA),
onTap: () {
print("hiii Data cell tap ${row.valueA}");
// Navigator.push(
// context, MaterialPageRoute(builder: (context) => Profile()));
},
),
DataCell(Text(row.valueC)),
DataCell(Text(row.valueD.toString())),
DataCell(Text(row.valueE)),
DataCell(Text(row.valueF)),
DataCell(Text(row.valueG)),
DataCell(Text(row.valueH)),
DataCell(Text(row.valueI)),
],
);
}
@override
int get rowCount => _rows.length;
@override
bool get isRowCountApproximate => false;
@override
int get selectedRowCount => _selectedCount;
}