Initialize project and update portal port configuration
Set default portal port to 8081, fix Dart build issue in cart screen, and update setup documentation. Co-Authored-By: Oz <oz-agent@warp.dev>
This commit is contained in:
121
lib/screens/home_screen.dart
Normal file
121
lib/screens/home_screen.dart
Normal file
@ -0,0 +1,121 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../services/auth_service.dart';
|
||||
import '../services/cart_service.dart';
|
||||
import '../services/product_repository.dart';
|
||||
import '../widgets/product_card.dart';
|
||||
import 'cart_screen.dart';
|
||||
import 'product_detail_screen.dart';
|
||||
import 'profile_screen.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cartCount = context.watch<CartService>().totalItems;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('E-Commerce Portal'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: 'Profile',
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const ProfileScreen()),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.person),
|
||||
),
|
||||
Stack(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'Cart',
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const CartScreen()),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.shopping_cart_outlined),
|
||||
),
|
||||
if (cartCount > 0)
|
||||
Positioned(
|
||||
right: 8,
|
||||
top: 8,
|
||||
child: Container(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'$cartCount',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 11,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Sign out',
|
||||
onPressed: () async {
|
||||
await AuthService.instance.signOut();
|
||||
},
|
||||
icon: const Icon(Icons.logout),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final width = constraints.maxWidth;
|
||||
int count = 1;
|
||||
if (width > 1200) {
|
||||
count = 4;
|
||||
} else if (width > 900) {
|
||||
count = 3;
|
||||
} else if (width > 600) {
|
||||
count = 2;
|
||||
}
|
||||
|
||||
return GridView.builder(
|
||||
itemCount: ProductRepository.products.length,
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: count,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 0.72,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final product = ProductRepository.products[index];
|
||||
return ProductCard(
|
||||
product: product,
|
||||
onView: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ProductDetailScreen(product: product),
|
||||
),
|
||||
);
|
||||
},
|
||||
onAddToCart: () {
|
||||
context.read<CartService>().addProduct(product);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('${product.name} added to cart')),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user