KonectarEvents/lib/contacts_module/custom_widget/custom_expansiontile.dart

213 lines
7.9 KiB
Dart
Raw Permalink Normal View History

2024-10-08 12:01:59 +00:00
import 'package:konectar_events/contacts_module/constants.dart';
import 'package:konectar_events/contacts_module/custom_widget/text.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_Certificate_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_aff_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_awards_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_education_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_email_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_event_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_location_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_pno_k2.dart';
import 'package:konectar_events/contacts_module/model_class/k2_api_model/kol_training_k2.dart';
import 'package:flutter/material.dart';
class CustomExpansionTile<T> extends StatefulWidget {
final String title;
final List<T> itemList;
final String buttonText;
final String field1;
final String field2;
final Function(T) onItemSelected;
const CustomExpansionTile({
Key? key,
required this.title,
required this.itemList,
required this.buttonText,
required this.onItemSelected,
required this.field1,
required this.field2,
}) : super(key: key);
@override
_CustomExpansionTileState createState() => _CustomExpansionTileState<T>();
}
class _CustomExpansionTileState<T> extends State<CustomExpansionTile<T>> {
bool _isExpanded = false;
@override
Widget build(BuildContext context) {
print("Chekingg_Field_one: ${widget.field1}");
return ListTileTheme(
dense: true,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Container(
child: Card(
margin: EdgeInsets.all(1.0),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(0.0),
),
color: Constants.k2color11,
child: ExpansionTile(
backgroundColor: Constants.k2color11,
initiallyExpanded: false,
maintainState: true,
onExpansionChanged: (bool expanded) {
setState(() {
_isExpanded = expanded;
});
},
trailing: Icon(
_isExpanded
? Icons.keyboard_arrow_up
: Icons.keyboard_arrow_down,
color: Colors.black,
),
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Text1(
title: widget.title,
txtcolor: Colors.black,
fontweight: FontWeight.normal,
txtfont: 16.0,
),
const SizedBox(width: 8.0),
Text1(
title: "(${widget.itemList.length})",
txtcolor: Colors.black,
fontweight: FontWeight.normal,
txtfont: 16.0,
),
],
),
children: [
Scrollbar(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
),
color: Colors.white,
child: DataTable(
showCheckboxColumn: false,
columns: [
DataColumn(
label: Expanded(
child: Text(
widget.field1 ?? 'Item',
style: TextStyle(fontWeight: FontWeight.w600),
softWrap: true,
),
),
),
DataColumn(
label: Expanded(
child: Text(
widget.field2 ?? 'Details',
style: TextStyle(fontWeight: FontWeight.w600),
),
),
),
],
rows: List.generate(widget.itemList.take(2).length,
(index) {
final item = widget.itemList[index];
return DataRow(
onSelectChanged: (value) {
widget.onItemSelected(widget.itemList[index]);
},
cells: [
DataCell(getdatacel1(item)),
DataCell(
getdatacel2(item),
),
],
);
}),
),
),
),
),
Container(
color: Colors.white,
child: Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: OutlinedButton(
onPressed: () {
// Handle the button action here
},
child: Text(
widget.buttonText,
style: TextStyle(color: Constants.k2color),
),
style: OutlinedButton.styleFrom(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
),
),
],
),
),
),
),
);
}
getdatacel1(T location) {
if (location is Data) {
return Text1(title: "${location.address1}");
} else if (location is DataPhno) {
return Text1(title: "${location.phoneTypeName}");
} else if (location is EmailData) {
return Text1(title: "${location.emailTypeName}");
} else if (location is TrainingList) {
return Text1(title: "${location.organizationId}");
} else if (location is EducationList) {
return Text1(title: "${location.organizationId}");
} else if (location is AwardsList) {
return Text1(title: "${location.name}");
} else if (location is CertificateList) {
return Text1(title: "${location.organizationId}");
} else if (location is AffList) {
return Text1(title: "${location.title}");
} else if (location is EventList) {
return Text1(title: "${location.name}");
}
}
getdatacel2(T location) {
if (location is Data) {
return Text1(title: "${location.postalCode}");
} else if (location is DataPhno) {
return Text1(title: "${location.number}");
} else if (location is EmailData) {
return Text1(title: "${location.email}");
} else if (location is TrainingList) {
return Text1(title: "${location.degree}");
} else if (location is EducationList) {
return Text1(title: "${location.degree}");
} else if (location is AwardsList) {
return Text1(title: "${location.startDate} ${location.endDate}");
} else if (location is CertificateList) {
return Text1(title: "${location.specialty}");
} else if (location is AffList) {
return Text1(title: "${location.role}");
} else if (location is EventList) {
return Text1(title: "${location.notes}");
}
}
}