add detail, fetch products, categories

This commit is contained in:
Phuoc Nguyen
2025-10-15 17:46:50 +07:00
parent 4038f8e8a6
commit 02e5fd4244
12 changed files with 814 additions and 84 deletions

View File

@@ -0,0 +1,131 @@
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import '../../domain/entities/product.dart';
import '../../../../shared/widgets/price_display.dart';
/// Product list item widget for list view
class ProductListItem extends StatelessWidget {
final Product product;
final VoidCallback? onTap;
const ProductListItem({
super.key,
required this.product,
this.onTap,
});
@override
Widget build(BuildContext context) {
return Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
child: InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Row(
children: [
// Product Image
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: SizedBox(
width: 80,
height: 80,
child: product.imageUrl != null
? CachedNetworkImage(
imageUrl: product.imageUrl!,
fit: BoxFit.cover,
placeholder: (context, url) => const Center(
child: CircularProgressIndicator(),
),
errorWidget: (context, url, error) => Container(
color: Theme.of(context)
.colorScheme
.surfaceContainerHighest,
child: Icon(
Icons.image_not_supported,
color:
Theme.of(context).colorScheme.onSurfaceVariant,
),
),
)
: Container(
color: Theme.of(context)
.colorScheme
.surfaceContainerHighest,
child: Icon(
Icons.inventory_2_outlined,
color:
Theme.of(context).colorScheme.onSurfaceVariant,
),
),
),
),
const SizedBox(width: 16),
// Product Info
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
product.name,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.w600,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
if (product.description.isNotEmpty)
Text(
product.description,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Row(
children: [
PriceDisplay(price: product.price),
const Spacer(),
// Stock Badge
Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: _getStockColor(context, product.stockQuantity),
borderRadius: BorderRadius.circular(12),
),
child: Text(
'Stock: ${product.stockQuantity}',
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
),
],
),
],
),
),
],
),
),
),
);
}
Color _getStockColor(BuildContext context, int stock) {
if (stock == 0) {
return Colors.red;
} else if (stock < 5) {
return Colors.orange;
} else {
return Colors.green;
}
}
}