drop down added of size
parent
67211fd2fa
commit
5be06c49ec
|
@ -0,0 +1,140 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
class SimpleDropdown<T> extends StatefulWidget {
|
||||
final List<T> items;
|
||||
final Function(T) onSelected;
|
||||
final T? selectedItem; // Change initialValue to selectedItem
|
||||
final double? width;
|
||||
final Color? borderClr;
|
||||
final Color? backClr;
|
||||
|
||||
const SimpleDropdown({
|
||||
super.key,
|
||||
required this.items,
|
||||
required this.onSelected,
|
||||
required this.selectedItem, // Make it required
|
||||
this.width,
|
||||
this.borderClr,
|
||||
this.backClr,
|
||||
});
|
||||
|
||||
@override
|
||||
_SimpleDropdownState<T> createState() => _SimpleDropdownState<T>();
|
||||
}
|
||||
|
||||
class _SimpleDropdownState<T> extends State<SimpleDropdown<T>> {
|
||||
OverlayEntry? overlayEntry;
|
||||
final LayerLink layerLink = LayerLink();
|
||||
bool isDropdownOpen = false;
|
||||
|
||||
@override
|
||||
void didUpdateWidget(SimpleDropdown<T> oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (oldWidget.selectedItem != widget.selectedItem) {
|
||||
setState(() {}); // Rebuild the dropdown when value changes
|
||||
}
|
||||
}
|
||||
|
||||
void _selectItem(T item) {
|
||||
widget.onSelected(item);
|
||||
_closeDropdown();
|
||||
}
|
||||
|
||||
void _toggleDropdown() {
|
||||
if (isDropdownOpen) {
|
||||
_closeDropdown();
|
||||
} else {
|
||||
_openDropdown();
|
||||
}
|
||||
}
|
||||
|
||||
void _openDropdown() {
|
||||
overlayEntry = _createOverlayEntry();
|
||||
Overlay.of(context).insert(overlayEntry!);
|
||||
setState(() {
|
||||
isDropdownOpen = true;
|
||||
});
|
||||
}
|
||||
|
||||
void _closeDropdown() {
|
||||
overlayEntry?.remove();
|
||||
overlayEntry = null;
|
||||
setState(() {
|
||||
isDropdownOpen = false;
|
||||
});
|
||||
}
|
||||
|
||||
OverlayEntry _createOverlayEntry() {
|
||||
final RenderBox renderBox = context.findRenderObject() as RenderBox;
|
||||
|
||||
return OverlayEntry(
|
||||
builder: (context) {
|
||||
return Positioned(
|
||||
width: widget.width ?? 110,
|
||||
child: CompositedTransformFollower(
|
||||
link: layerLink,
|
||||
showWhenUnlinked: false,
|
||||
offset: Offset(0, renderBox.size.height + 5),
|
||||
child: Material(
|
||||
elevation: 4,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
height: 160,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: Colors.grey, width: 1),
|
||||
),
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: widget.items.length,
|
||||
itemBuilder: (context, index) {
|
||||
final item = widget.items[index];
|
||||
return ListTile(
|
||||
minTileHeight: 24,
|
||||
title: Text(
|
||||
item.toString(),
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
onTap: () => _selectItem(item),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CompositedTransformTarget(
|
||||
link: layerLink,
|
||||
child: GestureDetector(
|
||||
onTap: _toggleDropdown,
|
||||
child: Container(
|
||||
width: widget.width ?? 110,
|
||||
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: widget.backClr ?? Colors.white,
|
||||
border: Border.all(color: widget.borderClr ?? Colors.grey, width: 1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
widget.selectedItem?.toString() ?? "Select Size",
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
Icon(Icons.keyboard_arrow_down_outlined, size: 20, color: Colors.black),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -5,7 +5,6 @@ import 'package:shayog/feature/presentation/screens/transporter/model/get_invoic
|
|||
import 'package:shayog/feature/presentation/screens/transporter/model/view_freight_bill_res_model.dart';
|
||||
import 'package:shayog/services/network/get_requests.dart';
|
||||
import 'package:shayog/services/network/post_request.dart';
|
||||
|
||||
import '../../../../../../components/common/common_model.dart';
|
||||
import '../../../../../../components/styles/app_strings.dart';
|
||||
|
||||
|
|
|
@ -3,15 +3,12 @@ import 'dart:io';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:shayog/components/common/custom_drop_down.dart';
|
||||
import 'package:shayog/components/common/custom_select_size.dart';
|
||||
import 'package:shayog/components/common/data_cell.dart';
|
||||
import 'package:shayog/components/styles/textStyles.dart';
|
||||
import 'package:shayog/feature/presentation/screens/transporter/view/sub_views/invoice_management_screen.dart';
|
||||
import 'package:shayog/feature/presentation/screens/transporter/view/sub_views/report_screen.dart';
|
||||
import 'package:shayog/feature/presentation/widgets/text_view.dart';
|
||||
|
||||
import '../../../../../../components/common/common_btn.dart';
|
||||
|
||||
import '../../../../../../components/styles/app_colors.dart';
|
||||
import '../../../../../../components/styles/app_images.dart';
|
||||
import '../../../../../../components/styles/app_strings.dart';
|
||||
|
@ -31,7 +28,6 @@ class TransportView extends StatefulWidget {
|
|||
}
|
||||
|
||||
class _TransportViewState extends State<TransportView> {
|
||||
// final ctrl = Get.put(TransportController());
|
||||
final ctrl = Get.put(TransportController(), permanent: true);
|
||||
final ScrollController horizontalScrollController = ScrollController();
|
||||
final ScrollController verticalScrollController = ScrollController();
|
||||
|
@ -59,6 +55,7 @@ class _TransportViewState extends State<TransportView> {
|
|||
onTap: () {
|
||||
ctrl.selectedIndex.value = index;
|
||||
ctrl.selectedUser.value = 0;
|
||||
ctrl.selectedUser.value = 0;
|
||||
},
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
|
@ -101,10 +98,8 @@ class _TransportViewState extends State<TransportView> {
|
|||
switch (ctrl.selectedIndex.value) {
|
||||
case 0:
|
||||
return _dashboardView();
|
||||
|
||||
case 1:
|
||||
return InvoiceManagement();
|
||||
|
||||
default:
|
||||
return ReportScreen();
|
||||
}
|
||||
|
@ -116,165 +111,6 @@ class _TransportViewState extends State<TransportView> {
|
|||
);
|
||||
}
|
||||
|
||||
_tableView() {
|
||||
return Column(
|
||||
children: [
|
||||
Scrollbar(
|
||||
thumbVisibility: true,
|
||||
controller: verticalScrollController,
|
||||
child: SingleChildScrollView(
|
||||
controller: verticalScrollController,
|
||||
child: Scrollbar(
|
||||
thumbVisibility: true,
|
||||
controller: horizontalScrollController,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
controller: horizontalScrollController,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: Colors.grey.shade400,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
child: DataTable(
|
||||
dataRowHeight: 40,
|
||||
headingRowHeight: 40,
|
||||
headingRowColor: WidgetStateProperty.all(AppColors.clrF2),
|
||||
border: TableBorder(
|
||||
horizontalInside: BorderSide(color: AppColors.clrGrey),
|
||||
verticalInside: BorderSide(color: AppColors.clrGrey),
|
||||
bottom: BorderSide(color: AppColors.clrGrey),
|
||||
left: BorderSide(color: AppColors.clrGrey),
|
||||
right: BorderSide(color: AppColors.clrGrey),
|
||||
top: BorderSide(color: AppColors.clrGrey),
|
||||
),
|
||||
columns: [
|
||||
dataColumn("Refrence No."),
|
||||
//dataColumn(AppStrings.productName, onSort: (_, __) => ctrl.changeSort(AppStrings.productName.toLowerCase())),
|
||||
dataColumn("Freight Bill No."),
|
||||
//dataColumn(AppStrings.getInvoiceDate),
|
||||
dataColumn("Freight Bill date"),
|
||||
dataColumn("Invoice No."),
|
||||
dataColumn("Invoice Date"),
|
||||
dataColumn("Invoice Amount"),
|
||||
dataColumn("CCN Amount"),
|
||||
dataColumn("View CCN"),
|
||||
dataColumn("Product Type"),
|
||||
dataColumn("View Invoice"),
|
||||
dataColumn("Add Signature"),
|
||||
],
|
||||
rows: List<DataRow>.generate(ctrl.getInvoiceData.length,
|
||||
(index) {
|
||||
final getInvoice = ctrl.getInvoiceData[index];
|
||||
return DataRow(
|
||||
cells: [
|
||||
editableCell(index, "${getInvoice.invoiceId}"),
|
||||
editableCell(index, getInvoice.freightbillCode),
|
||||
editableCell(
|
||||
index,
|
||||
DateFormat("dd MMMM yyyy").format(
|
||||
DateTime.parse('${getInvoice.createdOn}'))),
|
||||
editableCell(
|
||||
index, "${getInvoice.sapReferenceno ?? "-"}"),
|
||||
editableCell(
|
||||
index,
|
||||
DateFormat("d MMMM yyyy").format(DateTime.parse(
|
||||
'${getInvoice.shipmentCostDate}'))),
|
||||
editableCell(
|
||||
index, "${getInvoice.shipmentCost ?? "-"}"),
|
||||
editableCell(index, "${getInvoice.statusId ?? "-"}"),
|
||||
editableCell(index, getInvoice.materialCode ?? "-"),
|
||||
editableCell(index, getInvoice.materialDescription,
|
||||
isLink: true),
|
||||
editableCell(index, getInvoice.status ?? "-"),
|
||||
editableCell(index, getInvoice.plantCode ?? "-",
|
||||
isLink: true),
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.blue),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () {},
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.download,
|
||||
size: 16, color: Colors.blue),
|
||||
SizedBox(width: 4),
|
||||
Text('Download',
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 8),
|
||||
Container(
|
||||
padding: EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Colors.blue),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: InkWell(
|
||||
onTap: () => handleFileUpload(index),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.upload,
|
||||
size: 16, color: Colors.blue),
|
||||
SizedBox(width: 4),
|
||||
Text('Upload',
|
||||
style: TextStyle(
|
||||
color: Colors.blue,
|
||||
fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
//###################### This Function is used to close or cut uploaded File in Local #######################
|
||||
// if (uploadedFiles.containsKey(index))
|
||||
// IconButton(
|
||||
// icon: Icon(Icons.close, size: 16, color: Colors.red),
|
||||
// onPressed: () {
|
||||
// setState(() {
|
||||
// uploadedFiles.remove(index);
|
||||
// });
|
||||
// },
|
||||
// ),
|
||||
|
||||
//###########################################################################################################
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// CustomPagination(
|
||||
// currentPage: controller.currentPage.value,
|
||||
// totalPages: controller.totalPages.value,
|
||||
// onPageChanged: (int page) {
|
||||
// controller.onPageChanged(page);
|
||||
// },
|
||||
// ),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> handleFileUpload(int index) async {
|
||||
try {
|
||||
FilePickerResult? result = await FilePicker.platform.pickFiles(
|
||||
|
@ -398,28 +234,50 @@ class _TransportViewState extends State<TransportView> {
|
|||
),
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
if (ctrl.selectedUser.value == 0) {
|
||||
ctrl.toggleFilter();
|
||||
} else if (ctrl.selectedUser.value == 1) {
|
||||
ctrl.toggleViewFreight();
|
||||
} else if (ctrl.selectedUser.value == 2) {
|
||||
ctrl.togglePending();
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Image.asset(AppImages.filter,
|
||||
height: 16, width: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextView(
|
||||
text: AppStrings.filter,
|
||||
style: 12.txtBoldWhite,
|
||||
),
|
||||
onTap: () {
|
||||
if (ctrl.selectedUser.value == 0) {
|
||||
ctrl.toggleFilter();
|
||||
} else if (ctrl.selectedUser.value == 1) {
|
||||
ctrl.toggleViewFreight();
|
||||
} else if (ctrl.selectedUser.value == 2) {
|
||||
ctrl.togglePending();
|
||||
}
|
||||
},
|
||||
child: Row(
|
||||
children: [
|
||||
Image.asset(AppImages.filter,
|
||||
height: 16, width: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: TextView(
|
||||
text: AppStrings.filter,
|
||||
style: 12.txtBoldWhite,
|
||||
),
|
||||
],
|
||||
))
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => SimpleDropdown(
|
||||
|
||||
onSelected: (newValue) {
|
||||
ctrl.selectedDropdownItemViewFreight.value = newValue;
|
||||
ctrl.viewFreightView();
|
||||
},
|
||||
items: ctrl.selectElementSize,
|
||||
selectedItem: ctrl.selectedDropdownItemViewFreight.value,
|
||||
),
|
||||
),
|
||||
// Obx(() => SimpleDropdown<int>(
|
||||
// items: [1, 2, 3, 4],
|
||||
// selectedItem: ctrl. selectedDropdownItem.value, // Bind external state
|
||||
// onSelected: (val) => ctrl. selectedDropdownItem.value = val,
|
||||
// width: 150,
|
||||
// borderClr: Colors.blue,
|
||||
// )),
|
||||
|
||||
SizedBox(width: 10,),
|
||||
|
||||
],
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:shayog/components/styles/app_images.dart';
|
||||
import 'package:shayog/feature/presentation/screens/transporter/model/sub_freight_view_dialog_model.dart';
|
||||
|
@ -152,6 +153,9 @@ class TransportController extends GetxController {
|
|||
getInvoiceView();
|
||||
super.onInit();
|
||||
}
|
||||
Rxn<int> selectedDropdownItemViewFreight = Rxn<int>();
|
||||
|
||||
|
||||
|
||||
refreshApis() {
|
||||
getFreightBills();
|
||||
|
@ -159,6 +163,7 @@ class TransportController extends GetxController {
|
|||
grnPending();
|
||||
getSubFreightBillsView();
|
||||
postData();
|
||||
selectedDropdownItemViewFreight.value = null;
|
||||
}
|
||||
|
||||
getInvoiceView() async {
|
||||
|
@ -460,7 +465,13 @@ class TransportController extends GetxController {
|
|||
RxInt currentPageViewFreight = 1.obs;
|
||||
RxInt totalPagesViewFreight = 3.obs;
|
||||
final int limit = 10;
|
||||
|
||||
RxList selectElementSize = [
|
||||
4,
|
||||
8,
|
||||
12,
|
||||
16,
|
||||
20,
|
||||
].obs;
|
||||
|
||||
viewFreightView({int page = 0}) async {
|
||||
try {
|
||||
|
@ -477,7 +488,7 @@ class TransportController extends GetxController {
|
|||
};
|
||||
|
||||
var response = await PostRequests.viewFreightBill(
|
||||
page: page, size: 4, requestBody: requestBody);
|
||||
page: page, size: selectedDropdownItemViewFreight.value ?? 4, requestBody: requestBody);
|
||||
|
||||
if (response != null) {
|
||||
List<FreightBill> flattenedContent =
|
||||
|
@ -545,7 +556,8 @@ class TransportController extends GetxController {
|
|||
"grnToDate": "",
|
||||
};
|
||||
|
||||
print("🔎 Filter Request - Page: $page, Size: $size, Plant: ${selectPlantViewFreight.value}, "
|
||||
print(
|
||||
"🔎 Filter Request - Page: $page, Size: $size, Plant: ${selectPlantViewFreight.value}, "
|
||||
"Product: ${selectProductViewFreight.value}, Freight Bill: ${selectFreightBillValidate.value}");
|
||||
|
||||
var response = await PostRequests.viewFreightBill(
|
||||
|
@ -553,12 +565,13 @@ class TransportController extends GetxController {
|
|||
|
||||
if (response != null && response.content != null) {
|
||||
List<FreightBill> flattenedContent =
|
||||
response.content!.expand((list) => list).toList();
|
||||
response.content!.expand((list) => list).toList();
|
||||
|
||||
print("📌 Total records received: ${flattenedContent.length}");
|
||||
|
||||
if (page == 0) {
|
||||
freightBillData.assignAll(flattenedContent); // First page: Replace data
|
||||
freightBillData
|
||||
.assignAll(flattenedContent); // First page: Replace data
|
||||
} else {
|
||||
freightBillData.addAll(flattenedContent); // Next pages: Append data
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue