DiscoverModule/lib/ui_screen/trends.dart

227 lines
6.5 KiB
Dart

import 'package:discover_module/custom_widget/floating_btn.dart';
import 'package:discover_module/custom_widget/show_alert.dart';
import 'package:discover_module/ui_screen/ranking.dart';
import 'package:flutter/material.dart';
class Trends extends StatefulWidget {
const Trends({super.key});
@override
State<Trends> createState() => _TrendsState();
}
class _TrendsState extends State<Trends> {
late _DataSource _dataSource; // Instance variable for _DataSource
@override
void initState() {
super.initState();
print("hii_initState");
_dataSource = _DataSource(context);
}
@override
Widget build(BuildContext context) {
return SafeArea(
child: 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,
// actions: const [Text("jii")],
rowsPerPage: 5,
columns: const [
DataColumn(
label: Text('Name',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Last 5 Years',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Last 3 Years',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
DataColumn(
label: Text('Last 1 Year',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 14.0,
fontStyle: FontStyle.normal))),
],
source: _dataSource,
),
],
),
floatingActionButton: Visibility(
visible: true,
child: FloatingBtn(
icon: Icons.add,
title: "add",
onTap: () {
List<String> selectedRowIds = _dataSource.getSelectedRowIds();
// Do something with selectedRowIds
print('Selected Row IDstrndsss: $selectedRowIds');
for (int i = 0; i < selectedRowIds.length; i++) {
print("checking_value_istrends: ${selectedRowIds[i]}");
// _contactbox.put(i, selectedRowIds[i]);
HiveFunctions.createUser({
"name": selectedRowIds[i],
"org": "Azienda Ospedaliera di Padova",
"adrr": "Via Giustiniani 2, Padova, Veneto 35128, Italy",
"phone": "+390498212410X12",
"Pphone": "+390498212410X12",
"email": "Gerosa,Gino@gmail.com",
"affno": "75",
"eveno": "8",
"pubno": "251",
"trailno": "1"
});
}
showDialog(
context: context,
builder: (_) {
return Alert(data: "User Added Successfully");
});
},
)),
),
);
}
}
class _Row {
_Row(this.identifier, this.valueA, this.valueC, this.valueD, this.valueE);
final int identifier;
final String valueA;
final String valueC;
final IconData valueD;
final IconData valueE;
bool selected = false;
}
class _DataSource extends DataTableSource {
// _DataSource(this.context) {
// late BuildContext context;
// late List<_Row> _rows;
final BuildContext context;
late List<_Row> _rows;
final List<String> _selectedRowIds = [];
_DataSource(this.context) {
_rows = <_Row>[
for (int i = 0; i < 20; i++)
_Row(
i,
'Gerosa, Gino',
'1',
Icons.arrow_upward_sharp,
Icons.arrow_downward_rounded,
),
];
//}
}
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) {
// // print("hii");
// Navigator.push(
// context, MaterialPageRoute(builder: (context) => Profile()));
// },
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();
}
},
cells: [
DataCell(Text(row.valueA)),
DataCell(Text(row.valueC)),
const DataCell(
Row(
children: [
Icon(
Icons.arrow_drop_up,
color: Colors.green,
),
SizedBox(width: 8), // Adding some space between icon and text
Text("1"),
],
),
// Text
),
const DataCell(
Row(
children: [
Icon(
Icons.arrow_drop_down,
color: Colors.red,
),
SizedBox(width: 8), // Adding some space between icon and text
Text("1"),
],
),
),
],
);
}
@override
int get rowCount => _rows.length;
@override
bool get isRowCountApproximate => false;
@override
int get selectedRowCount => _selectedCount;
}