feat: order type
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
|
||||
import 'package:enaklo_pos/core/components/spaces.dart';
|
||||
import 'package:enaklo_pos/core/constants/colors.dart';
|
||||
import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart';
|
||||
import 'package:enaklo_pos/presentation/home/models/order_type.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class TypeDialog extends StatefulWidget {
|
||||
const TypeDialog({super.key});
|
||||
@@ -11,19 +14,30 @@ class TypeDialog extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _TypeDialogState extends State<TypeDialog> {
|
||||
String selectedType = 'dine_in';
|
||||
|
||||
List<Map<String, dynamic>> types = [
|
||||
{'value': 'dine_in', 'label': 'Dine In', 'icon': Icons.restaurant_outlined},
|
||||
{
|
||||
'value': 'dine_in',
|
||||
'label': 'Dine In',
|
||||
'icon': Icons.restaurant_outlined,
|
||||
'type': OrderType.dineIn,
|
||||
},
|
||||
{
|
||||
'value': 'take_away',
|
||||
'label': 'Take Away',
|
||||
'icon': Icons.takeout_dining_outlined
|
||||
'icon': Icons.takeout_dining_outlined,
|
||||
'type': OrderType.takeAway,
|
||||
},
|
||||
{
|
||||
'value': 'delivery',
|
||||
'label': 'Delivery',
|
||||
'icon': Icons.delivery_dining_outlined
|
||||
'icon': Icons.delivery_dining_outlined,
|
||||
'type': OrderType.delivery,
|
||||
},
|
||||
{
|
||||
'value': 'grab',
|
||||
'label': 'Grab',
|
||||
'icon': Icons.two_wheeler,
|
||||
'type': OrderType.grab,
|
||||
},
|
||||
];
|
||||
|
||||
@@ -32,34 +46,56 @@ class _TypeDialogState extends State<TypeDialog> {
|
||||
return CustomModalDialog(
|
||||
title: 'Pilih Tipe',
|
||||
subtitle: 'Silahkan pilih tipe yang sesuai',
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: List.generate(types.length, (index) {
|
||||
return _buildItem(context, types[index]);
|
||||
}),
|
||||
),
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
|
||||
child: BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||
builder: (context, state) {
|
||||
return state.maybeWhen(
|
||||
orElse: () => const SizedBox.shrink(),
|
||||
loaded: (items,
|
||||
discountModel,
|
||||
discount,
|
||||
discountAmount,
|
||||
tax,
|
||||
serviceCharge,
|
||||
totalQuantity,
|
||||
totalPrice,
|
||||
draftName,
|
||||
orderType) {
|
||||
return Column(
|
||||
children: List.generate(types.length, (index) {
|
||||
return _buildItem(
|
||||
context,
|
||||
types[index],
|
||||
selectedType: orderType,
|
||||
);
|
||||
}),
|
||||
);
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildItem(BuildContext context, Map<String, dynamic> type) {
|
||||
Widget _buildItem(BuildContext context, Map<String, dynamic> type,
|
||||
{required OrderType selectedType}) {
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedType = type['value']!;
|
||||
});
|
||||
context.read<CheckoutBloc>().add(
|
||||
CheckoutEvent.updateOrderType(type['type']),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
||||
margin: const EdgeInsets.only(bottom: 8.0),
|
||||
decoration: BoxDecoration(
|
||||
color: selectedType == type['value']
|
||||
color: selectedType == type['type']
|
||||
? AppColors.primary
|
||||
: AppColors.white,
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
border: Border.all(
|
||||
color: selectedType == type['value']
|
||||
color: selectedType == type['type']
|
||||
? AppColors.primary
|
||||
: AppColors.grey,
|
||||
width: 1.0,
|
||||
@@ -68,7 +104,7 @@ class _TypeDialogState extends State<TypeDialog> {
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(type['icon'],
|
||||
color: selectedType == type['value']
|
||||
color: selectedType == type['type']
|
||||
? AppColors.white
|
||||
: AppColors.black),
|
||||
SpaceWidth(12.0),
|
||||
@@ -77,7 +113,7 @@ class _TypeDialogState extends State<TypeDialog> {
|
||||
type['label']!,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: selectedType == type['value']
|
||||
color: selectedType == type['type']
|
||||
? AppColors.white
|
||||
: AppColors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
||||
Reference in New Issue
Block a user