update total price
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
import '../../../application/checkout/checkout_form/checkout_form_bloc.dart';
|
||||
import '../../../common/extension/extension.dart';
|
||||
import '../../../common/theme/theme.dart';
|
||||
import '../../../domain/product/product.dart';
|
||||
@@ -17,9 +19,9 @@ class ProductCard extends StatelessWidget {
|
||||
onTap: () {
|
||||
if (product.isActive == true) {
|
||||
if (product.variants.isEmpty) {
|
||||
// context.read<CheckoutBloc>().add(
|
||||
// CheckoutEvent.addItem(data, null),
|
||||
// );
|
||||
context.read<CheckoutFormBloc>().add(
|
||||
CheckoutFormEvent.addItem(product, null),
|
||||
);
|
||||
} else {
|
||||
showDialog(
|
||||
context: context,
|
||||
@@ -85,28 +87,40 @@ class ProductCard extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
|
||||
Positioned(
|
||||
top: 4,
|
||||
right: 4,
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(9.0)),
|
||||
color: AppColor.primary,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
0.toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
BlocBuilder<CheckoutFormBloc, CheckoutFormState>(
|
||||
builder: (context, state) {
|
||||
final totalQuantity = state.items
|
||||
.where((item) => item.product.id == product.id)
|
||||
.map((item) => item.quantity)
|
||||
.fold(0, (sum, qty) => sum + qty);
|
||||
|
||||
if (totalQuantity == 0) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
return Positioned(
|
||||
top: 4,
|
||||
right: 4,
|
||||
child: Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: const BoxDecoration(
|
||||
borderRadius: BorderRadius.all(Radius.circular(9.0)),
|
||||
color: AppColor.primary,
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
totalQuantity.toString(),
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
if (product.isActive == false)
|
||||
Container(
|
||||
|
||||
Reference in New Issue
Block a user