feat: order type
This commit is contained in:
parent
7b64ca2bb3
commit
09a812d417
@ -15,4 +15,12 @@ extension StringExt on String {
|
|||||||
decimalDigits: 0,
|
decimalDigits: 0,
|
||||||
).format(parsedValue);
|
).format(parsedValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String toTitleCase() {
|
||||||
|
if (isEmpty) return '';
|
||||||
|
return split(' ').map((word) {
|
||||||
|
if (word.isEmpty) return '';
|
||||||
|
return word[0].toUpperCase() + word.substring(1).toLowerCase();
|
||||||
|
}).join(' ');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,10 @@
|
|||||||
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
|
import 'package:enaklo_pos/core/components/custom_modal_dialog.dart';
|
||||||
import 'package:enaklo_pos/core/components/spaces.dart';
|
import 'package:enaklo_pos/core/components/spaces.dart';
|
||||||
import 'package:enaklo_pos/core/constants/colors.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/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
class TypeDialog extends StatefulWidget {
|
class TypeDialog extends StatefulWidget {
|
||||||
const TypeDialog({super.key});
|
const TypeDialog({super.key});
|
||||||
@ -11,19 +14,30 @@ class TypeDialog extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _TypeDialogState extends State<TypeDialog> {
|
class _TypeDialogState extends State<TypeDialog> {
|
||||||
String selectedType = 'dine_in';
|
|
||||||
|
|
||||||
List<Map<String, dynamic>> types = [
|
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',
|
'value': 'take_away',
|
||||||
'label': 'Take Away',
|
'label': 'Take Away',
|
||||||
'icon': Icons.takeout_dining_outlined
|
'icon': Icons.takeout_dining_outlined,
|
||||||
|
'type': OrderType.takeAway,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'value': 'delivery',
|
'value': 'delivery',
|
||||||
'label': '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(
|
return CustomModalDialog(
|
||||||
title: 'Pilih Tipe',
|
title: 'Pilih Tipe',
|
||||||
subtitle: 'Silahkan pilih tipe yang sesuai',
|
subtitle: 'Silahkan pilih tipe yang sesuai',
|
||||||
child: Padding(
|
contentPadding:
|
||||||
padding: const EdgeInsets.all(16.0),
|
const EdgeInsets.symmetric(horizontal: 16.0, vertical: 24.0),
|
||||||
child: Column(
|
child: BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||||
children: List.generate(types.length, (index) {
|
builder: (context, state) {
|
||||||
return _buildItem(context, types[index]);
|
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(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
context.read<CheckoutBloc>().add(
|
||||||
selectedType = type['value']!;
|
CheckoutEvent.updateOrderType(type['type']),
|
||||||
});
|
);
|
||||||
|
Navigator.pop(context);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
padding: const EdgeInsets.symmetric(vertical: 12.0, horizontal: 16.0),
|
||||||
margin: const EdgeInsets.only(bottom: 8.0),
|
margin: const EdgeInsets.only(bottom: 8.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: selectedType == type['value']
|
color: selectedType == type['type']
|
||||||
? AppColors.primary
|
? AppColors.primary
|
||||||
: AppColors.white,
|
: AppColors.white,
|
||||||
borderRadius: BorderRadius.circular(8.0),
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: selectedType == type['value']
|
color: selectedType == type['type']
|
||||||
? AppColors.primary
|
? AppColors.primary
|
||||||
: AppColors.grey,
|
: AppColors.grey,
|
||||||
width: 1.0,
|
width: 1.0,
|
||||||
@ -68,7 +104,7 @@ class _TypeDialogState extends State<TypeDialog> {
|
|||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(type['icon'],
|
Icon(type['icon'],
|
||||||
color: selectedType == type['value']
|
color: selectedType == type['type']
|
||||||
? AppColors.white
|
? AppColors.white
|
||||||
: AppColors.black),
|
: AppColors.black),
|
||||||
SpaceWidth(12.0),
|
SpaceWidth(12.0),
|
||||||
@ -77,7 +113,7 @@ class _TypeDialogState extends State<TypeDialog> {
|
|||||||
type['label']!,
|
type['label']!,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
color: selectedType == type['value']
|
color: selectedType == type['type']
|
||||||
? AppColors.white
|
? AppColors.white
|
||||||
: AppColors.black,
|
: AppColors.black,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
|||||||
@ -118,6 +118,44 @@ class _ConfirmPaymentPageState extends State<ConfirmPaymentPage> {
|
|||||||
subtitle: widget.isTable
|
subtitle: widget.isTable
|
||||||
? 'Orders Table ${widget.table?.tableName}'
|
? 'Orders Table ${widget.table?.tableName}'
|
||||||
: 'Orders #1',
|
: 'Orders #1',
|
||||||
|
actionWidget: [
|
||||||
|
BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
return state.maybeWhen(
|
||||||
|
orElse: () => const SizedBox(),
|
||||||
|
loaded: (products,
|
||||||
|
discountModel,
|
||||||
|
discount,
|
||||||
|
discountAmount,
|
||||||
|
tax,
|
||||||
|
serviceCharge,
|
||||||
|
totalQuantity,
|
||||||
|
totalPrice,
|
||||||
|
draftName,
|
||||||
|
orderType) {
|
||||||
|
return Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(8.0),
|
||||||
|
border: Border.all(
|
||||||
|
color: AppColors.primary,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.all(8.0),
|
||||||
|
child: Text(
|
||||||
|
orderType.value,
|
||||||
|
style: TextStyle(
|
||||||
|
color: AppColors.primary,
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.all(16.0).copyWith(bottom: 8),
|
padding: const EdgeInsets.all(16.0).copyWith(bottom: 8),
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
import 'package:enaklo_pos/core/components/buttons.dart';
|
import 'package:enaklo_pos/core/components/buttons.dart';
|
||||||
import 'package:enaklo_pos/core/constants/colors.dart';
|
import 'package:enaklo_pos/core/constants/colors.dart';
|
||||||
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
|
||||||
|
import 'package:enaklo_pos/core/extensions/string_ext.dart';
|
||||||
import 'package:enaklo_pos/data/models/response/table_model.dart';
|
import 'package:enaklo_pos/data/models/response/table_model.dart';
|
||||||
|
import 'package:enaklo_pos/presentation/home/bloc/checkout/checkout_bloc.dart';
|
||||||
import 'package:enaklo_pos/presentation/home/dialog/type_dialog.dart';
|
import 'package:enaklo_pos/presentation/home/dialog/type_dialog.dart';
|
||||||
import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart';
|
import 'package:enaklo_pos/presentation/home/pages/dashboard_page.dart';
|
||||||
import 'package:enaklo_pos/presentation/sales/pages/sales_page.dart';
|
import 'package:enaklo_pos/presentation/sales/pages/sales_page.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
|
||||||
class HomeRightTitle extends StatelessWidget {
|
class HomeRightTitle extends StatelessWidget {
|
||||||
final TableModel? table;
|
final TableModel? table;
|
||||||
@ -72,25 +75,43 @@ class HomeRightTitle extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Button.filled(
|
child: BlocBuilder<CheckoutBloc, CheckoutState>(
|
||||||
width: 180.0,
|
builder: (context, state) {
|
||||||
height: 40,
|
return state.maybeWhen(
|
||||||
elevation: 0,
|
orElse: () => const SizedBox.shrink(),
|
||||||
onPressed: () {
|
loaded: (items,
|
||||||
showDialog(
|
discountModel,
|
||||||
context: context,
|
discount,
|
||||||
builder: (context) {
|
discountAmount,
|
||||||
return TypeDialog();
|
tax,
|
||||||
});
|
serviceCharge,
|
||||||
|
totalQuantity,
|
||||||
|
totalPrice,
|
||||||
|
draftName,
|
||||||
|
orderType) {
|
||||||
|
return Button.filled(
|
||||||
|
width: 180.0,
|
||||||
|
height: 40,
|
||||||
|
elevation: 0,
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return TypeDialog();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
icon: Icon(
|
||||||
|
Icons.dinner_dining_outlined,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 24,
|
||||||
|
),
|
||||||
|
label: orderType.value.toTitleCase(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
},
|
},
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
icon: Icon(
|
|
||||||
Icons.dinner_dining_outlined,
|
|
||||||
color: Colors.white,
|
|
||||||
size: 24,
|
|
||||||
),
|
|
||||||
label: 'Dine In',
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user