add firebase, add screen flow
This commit is contained in:
@@ -7,9 +7,11 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:worker/core/services/analytics_service.dart';
|
||||
import 'package:worker/core/widgets/loading_indicator.dart';
|
||||
import 'package:worker/core/constants/ui_constants.dart';
|
||||
import 'package:worker/core/theme/colors.dart';
|
||||
import 'package:worker/features/cart/presentation/providers/cart_provider.dart';
|
||||
import 'package:worker/features/favorites/presentation/providers/favorites_provider.dart';
|
||||
import 'package:worker/features/products/domain/entities/product.dart';
|
||||
import 'package:worker/features/products/presentation/providers/products_provider.dart';
|
||||
@@ -154,8 +156,25 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void _addToCart(Product product) {
|
||||
// TODO: Add to cart logic
|
||||
void _addToCart(Product product) async {
|
||||
// Add to cart via provider
|
||||
await ref.read(cartProvider.notifier).addToCart(
|
||||
product,
|
||||
quantity: _quantity.toDouble(),
|
||||
);
|
||||
|
||||
// Log analytics event
|
||||
await AnalyticsService.logAddToCart(
|
||||
productId: product.productId,
|
||||
productName: product.name,
|
||||
price: product.basePrice,
|
||||
quantity: _quantity,
|
||||
brand: product.itemGroupName,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
ScaffoldMessenger.of(context).clearSnackBars();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
@@ -165,7 +184,7 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
action: SnackBarAction(
|
||||
label: 'Xem giỏ hàng',
|
||||
onPressed: () {
|
||||
// TODO: Navigate to cart
|
||||
context.push('/cart');
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -245,20 +264,15 @@ class _ProductDetailPageState extends ConsumerState<ProductDetailPage> {
|
||||
),
|
||||
|
||||
// Sticky Action Bar
|
||||
Positioned(
|
||||
bottom: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
child: StickyActionBar(
|
||||
quantity: _quantity,
|
||||
unit: 'm²',
|
||||
conversionOfSm: product.conversionOfSm,
|
||||
uomFromIntroAttributes: product.getIntroAttribute('UOM'),
|
||||
onIncrease: _increaseQuantity,
|
||||
onDecrease: _decreaseQuantity,
|
||||
onQuantityChanged: _updateQuantity,
|
||||
onAddToCart: () => _addToCart(product),
|
||||
),
|
||||
StickyActionBar(
|
||||
quantity: _quantity,
|
||||
unit: 'm²',
|
||||
conversionOfSm: product.conversionOfSm,
|
||||
uomFromIntroAttributes: product.getIntroAttribute('UOM'),
|
||||
onIncrease: _increaseQuantity,
|
||||
onDecrease: _decreaseQuantity,
|
||||
onQuantityChanged: _updateQuantity,
|
||||
onAddToCart: () => _addToCart(product),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:worker/core/services/analytics_service.dart';
|
||||
import 'package:worker/core/widgets/loading_indicator.dart';
|
||||
import 'package:worker/core/constants/ui_constants.dart';
|
||||
import 'package:worker/core/router/app_router.dart';
|
||||
@@ -44,7 +45,13 @@ class ProductsPage extends ConsumerWidget {
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: FaIcon(FontAwesomeIcons.arrowLeft, color: colorScheme.onSurface, size: 20),
|
||||
onPressed: () => context.pop(),
|
||||
onPressed: () {
|
||||
if (context.canPop()) {
|
||||
context.pop();
|
||||
} else {
|
||||
context.go(RouteNames.home);
|
||||
}
|
||||
},
|
||||
),
|
||||
title: Text('Sản phẩm', style: TextStyle(color: colorScheme.onSurface)),
|
||||
elevation: AppBarSpecs.elevation,
|
||||
@@ -135,6 +142,14 @@ class ProductsPage extends ConsumerWidget {
|
||||
// Add to cart
|
||||
ref.read(cartProvider.notifier).addToCart(product);
|
||||
|
||||
AnalyticsService.logAddToCart(
|
||||
productId: product.productId,
|
||||
productName: product.name,
|
||||
price: product.basePrice,
|
||||
quantity: 1,
|
||||
brand: product.itemGroupName,
|
||||
);
|
||||
|
||||
// Show SnackBar with manual dismissal
|
||||
final messenger = ScaffoldMessenger.of(context)
|
||||
..clearSnackBars();
|
||||
|
||||
Reference in New Issue
Block a user