feat: update dropdown

This commit is contained in:
efrilm
2025-08-06 19:28:51 +07:00
parent 5e9d5040e7
commit c667584b11
6 changed files with 414 additions and 96 deletions
@@ -3255,10 +3255,10 @@ class __$$UpdateDeliveryTypeImplCopyWithImpl<$Res>
@pragma('vm:prefer-inline')
@override
$Res call({
Object? delivery = freezed,
Object? delivery = null,
}) {
return _then(_$UpdateDeliveryTypeImpl(
freezed == delivery
null == delivery
? _value.delivery
: delivery // ignore: cast_nullable_to_non_nullable
as DeliveryModel,
@@ -3284,12 +3284,12 @@ class _$UpdateDeliveryTypeImpl implements _UpdateDeliveryType {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$UpdateDeliveryTypeImpl &&
const DeepCollectionEquality().equals(other.delivery, delivery));
(identical(other.delivery, delivery) ||
other.delivery == delivery));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(delivery));
int get hashCode => Object.hash(runtimeType, delivery);
/// Create a copy of CheckoutEvent
/// with the given fields replaced by the non-null parameter values.
@@ -4063,8 +4063,8 @@ class _$LoadedImpl implements _Loaded {
other.draftName == draftName) &&
(identical(other.orderType, orderType) ||
other.orderType == orderType) &&
const DeepCollectionEquality()
.equals(other.deliveryType, deliveryType));
(identical(other.deliveryType, deliveryType) ||
other.deliveryType == deliveryType));
}
@override
@@ -4080,7 +4080,7 @@ class _$LoadedImpl implements _Loaded {
totalPrice,
draftName,
orderType,
const DeepCollectionEquality().hash(deliveryType));
deliveryType);
/// Create a copy of CheckoutState
/// with the given fields replaced by the non-null parameter values.
@@ -1,3 +1,6 @@
import 'dart:developer';
import 'package:dropdown_search/dropdown_search.dart';
import 'package:enaklo_pos/core/components/buttons.dart';
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
import 'package:enaklo_pos/core/components/flushbar.dart';
@@ -31,6 +34,7 @@ class _PaymentAddOrderDialogState extends State<PaymentAddOrderDialog> {
'pending',
dateFrom: DateTime.now(),
dateTo: DateTime.now(),
limit: 20,
),
);
}
@@ -97,40 +101,183 @@ class _PaymentAddOrderDialogState extends State<PaymentAddOrderDialog> {
);
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).primaryColor,
width: 2,
return DropdownSearch<Order>(
items: orders,
selectedItem: selectOrder,
// Dropdown properties
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: "Pilih Meja",
hintStyle: TextStyle(
color: Colors.grey.shade600,
fontSize: 14,
),
prefixIcon: Icon(
Icons.category_outlined,
color: Colors.grey.shade500,
size: 20,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade300,
width: 1.5,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade300,
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.blue.shade400,
width: 2,
),
),
filled: true,
fillColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<Order>(
isExpanded: true,
value: availableOrders.firstWhere(
(t) => t.id == selectOrder?.id,
orElse: () => availableOrders.first,
// Popup properties
popupProps: PopupProps.menu(
showSearchBox: true,
searchFieldProps: TextFieldProps(
decoration: InputDecoration(
hintText: "Cari meja...",
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
onChanged: (Order? newValue) {
setState(() {
selectOrder = newValue;
});
},
items: availableOrders
.map<DropdownMenuItem<Order>>(
(Order value) => DropdownMenuItem<Order>(
value: value,
child: Text(
"${value.tableNumber ?? ""} - ${value.metadata?['customer_name'] ?? ""}",
),
menuProps: MenuProps(
backgroundColor: Colors.white,
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
itemBuilder: (context, order, isSelected) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
decoration: BoxDecoration(
color: isSelected
? Colors.blue.shade50
: Colors.transparent,
border: Border(
bottom: BorderSide(
color: Colors.grey.shade100,
width: 0.5,
),
),
),
child: Row(
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: isSelected
? Colors.blue.shade600
: Colors.grey.shade400,
shape: BoxShape.circle,
),
),
)
.toList(),
),
const SizedBox(width: 12),
Expanded(
child: Text(
"${order.tableNumber ?? ""} - ${order.metadata?['customer_name']}",
style: TextStyle(
fontSize: 14,
fontWeight: isSelected
? FontWeight.w600
: FontWeight.w500,
color: isSelected
? Colors.blue.shade700
: Colors.black87,
),
),
),
if (isSelected)
Icon(
Icons.check,
color: Colors.blue.shade600,
size: 18,
),
],
),
);
},
emptyBuilder: (context, searchEntry) {
return Container(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.search_off,
color: Colors.grey.shade400,
size: 48,
),
const SizedBox(height: 12),
Text(
searchEntry.isEmpty
? "Tidak ada meja tersedia"
: "Tidak ditemukan meja dengan '${searchEntry}'",
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
),
);
},
),
// Item as string (for search functionality)
itemAsString: (Order order) => order.tableNumber ?? "",
// Comparison function
compareFn: (Order? item1, Order? item2) {
return item1?.id == item2?.id;
},
// On changed callback
onChanged: (Order? selectedOrder) {
if (selectedOrder != null) {
setState(() {
selectOrder = selectedOrder;
});
log("selectOrder: ${selectOrder!.tableNumber}");
}
},
// Validator (optional)
validator: (Order? value) {
if (value == null) {
return "Meja harus dipilih";
}
return null;
},
);
},
);
@@ -1,3 +1,6 @@
import 'dart:developer';
import 'package:dropdown_search/dropdown_search.dart';
import 'package:enaklo_pos/core/components/buttons.dart';
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
import 'package:enaklo_pos/core/components/flushbar.dart';
@@ -103,39 +106,183 @@ class _PaymentSaveDialogState extends State<PaymentSaveDialog> {
);
}
return Container(
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
border: Border.all(
color: Theme.of(context).primaryColor,
width: 2,
),
),
child: DropdownButtonHideUnderline(
child: DropdownButton<TableModel>(
isExpanded: true,
value: availableTables.firstWhere(
(t) => t.id == selectTable?.id,
orElse: () => availableTables.first,
return DropdownSearch<TableModel>(
items: tables,
selectedItem: selectTable,
// Dropdown properties
dropdownDecoratorProps: DropDownDecoratorProps(
dropdownSearchDecoration: InputDecoration(
hintText: "Pilih meja",
hintStyle: TextStyle(
color: Colors.grey.shade600,
fontSize: 14,
),
prefixIcon: Icon(
Icons.category_outlined,
color: Colors.grey.shade500,
size: 20,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade300,
width: 1.5,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.grey.shade300,
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(
color: Colors.blue.shade400,
width: 2,
),
),
filled: true,
fillColor: Colors.white,
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 16,
),
onChanged: (TableModel? newValue) {
setState(() {
selectTable = newValue;
});
},
items: availableTables
.map<DropdownMenuItem<TableModel>>(
(TableModel value) =>
DropdownMenuItem<TableModel>(
value: value,
child: Text(value.tableName ?? ""),
),
)
.toList(),
),
),
// Popup properties
popupProps: PopupProps.menu(
showSearchBox: true,
searchFieldProps: TextFieldProps(
decoration: InputDecoration(
hintText: "Cari meja...",
prefixIcon: const Icon(Icons.search),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
),
),
menuProps: MenuProps(
backgroundColor: Colors.white,
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
itemBuilder: (context, category, isSelected) {
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
decoration: BoxDecoration(
color: isSelected
? Colors.blue.shade50
: Colors.transparent,
border: Border(
bottom: BorderSide(
color: Colors.grey.shade100,
width: 0.5,
),
),
),
child: Row(
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: isSelected
? Colors.blue.shade600
: Colors.grey.shade400,
shape: BoxShape.circle,
),
),
const SizedBox(width: 12),
Expanded(
child: Text(
category.tableName ?? "",
style: TextStyle(
fontSize: 14,
fontWeight: isSelected
? FontWeight.w600
: FontWeight.w500,
color: isSelected
? Colors.blue.shade700
: Colors.black87,
),
),
),
if (isSelected)
Icon(
Icons.check,
color: Colors.blue.shade600,
size: 18,
),
],
),
);
},
emptyBuilder: (context, searchEntry) {
return Container(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.search_off,
color: Colors.grey.shade400,
size: 48,
),
const SizedBox(height: 12),
Text(
searchEntry.isEmpty
? "Tidak ada meja tersedia"
: "Tidak ditemukan meja dengan '${searchEntry}'",
style: TextStyle(
color: Colors.grey.shade600,
fontSize: 14,
),
textAlign: TextAlign.center,
),
],
),
);
},
),
// Item as string (for search functionality)
itemAsString: (TableModel table) => table.tableName ?? "",
// Comparison function
compareFn: (TableModel? item1, TableModel? item2) {
return item1?.id == item2?.id;
},
// On changed callback
onChanged: (TableModel? selectedTable) {
if (selectedTable != null) {
setState(() {
selectTable = selectedTable;
});
log("selectTable: ${selectTable!.tableName}");
}
},
// Validator (optional)
validator: (TableModel? value) {
if (value == null) {
return "Meja harus dipilih";
}
return null;
},
);
},
);