feat: slicing home page

This commit is contained in:
efrilm
2025-07-31 19:25:45 +07:00
parent 73320561b0
commit 445a22a5a4
13 changed files with 1231 additions and 696 deletions
@@ -1,3 +1,5 @@
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:enaklo_pos/data/models/response/discount_response_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
@@ -25,29 +27,38 @@ class _DiscountDialogState extends State<DiscountDialog> {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Stack(
alignment: Alignment.center,
backgroundColor: AppColors.white,
title: Row(
children: [
const Text(
'DISKON',
style: TextStyle(
color: AppColors.primary,
fontSize: 28,
fontWeight: FontWeight.w600,
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Pilih Diskon',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: AppColors.black,
),
),
const SizedBox(height: 4.0),
Text(
'Pilih diskon yang ingin diterapkan pada pesanan',
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
],
),
),
Align(
alignment: Alignment.centerRight,
child: IconButton(
onPressed: () {
context.pop();
},
icon: const Icon(
Icons.cancel,
color: AppColors.primary,
size: 30.0,
),
),
SpaceWidth(12),
IconButton(
icon: const Icon(Icons.close, color: AppColors.black),
onPressed: () {
context.pop();
},
),
],
),
@@ -63,30 +74,7 @@ class _DiscountDialogState extends State<DiscountDialog> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: discounts
.map(
(discount) => ListTile(
title: Text('Nama Diskon: ${discount.name}'),
subtitle: Text('Potongan harga (${discount.value}%)'),
contentPadding: EdgeInsets.zero,
textColor: AppColors.primary,
trailing: Checkbox(
value: discount.id == discountIdSelected,
onChanged: (value) {
setState(() {
discountIdSelected = discount.id!;
context.read<CheckoutBloc>().add(
CheckoutEvent.addDiscount(
discount,
),
);
});
},
),
onTap: () {
// context.pop();
},
),
)
.map((discount) => _buildDiscountItem(discount))
.toList(),
);
},
@@ -95,4 +83,58 @@ class _DiscountDialogState extends State<DiscountDialog> {
),
);
}
Widget _buildDiscountItem(Discount discount) {
return GestureDetector(
onTap: () {
setState(() {
discountIdSelected = discount.id!;
context.read<CheckoutBloc>().add(
CheckoutEvent.addDiscount(
discount,
),
);
});
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
margin: const EdgeInsets.only(bottom: 8.0),
decoration: BoxDecoration(
color: discountIdSelected == discount.id
? AppColors.primary
: AppColors.white,
borderRadius: BorderRadius.circular(8.0),
border: Border.all(
color: discountIdSelected == discount.id
? AppColors.primary
: AppColors.grey,
width: 1.0,
),
),
child: Row(
children: [
Expanded(
child: Text(
"${discount.name} (${discount.value})",
style: TextStyle(
fontSize: 16,
color: discountIdSelected == discount.id
? AppColors.white
: AppColors.black,
fontWeight: FontWeight.w500,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
SpaceWidth(12.0),
Icon(Icons.check_circle,
color: discountIdSelected == discount.id
? AppColors.green
: Colors.transparent),
],
),
),
);
}
}
@@ -1,3 +1,4 @@
import 'package:enaklo_pos/core/components/spaces.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:enaklo_pos/core/extensions/build_context_ext.dart';
@@ -11,27 +12,38 @@ class ServiceDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return AlertDialog(
title: Stack(
alignment: Alignment.center,
backgroundColor: AppColors.white,
title: Row(
children: [
const Text(
'LAYANAN',
style: TextStyle(
color: AppColors.primary,
fontSize: 28,
fontWeight: FontWeight.w600,
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Pilih Layanan',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: AppColors.black,
),
),
const SizedBox(height: 4.0),
Text(
'Pilih layanan yang ingin diterapkan pada pesanan',
style: TextStyle(
fontSize: 14,
color: Colors.grey,
),
),
],
),
),
Align(
alignment: Alignment.centerRight,
child: IconButton(
onPressed: () => context.pop(),
icon: const Icon(
Icons.cancel,
color: AppColors.primary,
size: 30.0,
),
),
SpaceWidth(12),
IconButton(
icon: const Icon(Icons.close, color: AppColors.black),
onPressed: () {
context.pop();
},
),
],
),
@@ -44,23 +56,8 @@ class ServiceDialog extends StatelessWidget {
return state.maybeWhen(
initial: () => const SizedBox(),
loading: () => const Center(child: CircularProgressIndicator()),
loaded: (data, a, b, c, d, service, e, f, g, orderType) => ListTile(
title: Text('Presentase ($service%)'),
subtitle: const Text('Biaya layanan'),
contentPadding: EdgeInsets.zero,
textColor: AppColors.primary,
trailing: Checkbox(
value: service > 0,
onChanged: (value) {
context.read<CheckoutBloc>().add(
CheckoutEvent.addServiceCharge(service > 0 ? 0 : service),
);
},
),
onTap: () {
context.pop();
},
),
loaded: (data, a, b, c, d, service, e, f, g, orderType) =>
_buildServiceItem(context, service),
orElse: () => const SizedBox(),
);
},
@@ -69,4 +66,47 @@ class ServiceDialog extends StatelessWidget {
),
);
}
Widget _buildServiceItem(BuildContext context, int service) {
return GestureDetector(
onTap: () {
context.read<CheckoutBloc>().add(
CheckoutEvent.addServiceCharge(service > 0 ? 0 : service),
);
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 12.0),
margin: const EdgeInsets.only(bottom: 8.0),
decoration: BoxDecoration(
color: AppColors.primary,
borderRadius: BorderRadius.circular(8.0),
border: Border.all(
color: AppColors.primary,
width: 1.0,
),
),
child: Row(
children: [
Expanded(
child: Text(
"Biaya layanan ($service%)",
style: TextStyle(
fontSize: 16,
color: AppColors.white,
fontWeight: FontWeight.w500,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
SpaceWidth(12.0),
Icon(
Icons.check_circle,
color: AppColors.green,
),
],
),
),
);
}
}