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:
99
lib/screens/cart_screen.dart
Normal file
99
lib/screens/cart_screen.dart
Normal file
@ -0,0 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../services/cart_service.dart';
|
||||
import 'checkout_screen.dart';
|
||||
|
||||
class CartScreen extends StatelessWidget {
|
||||
const CartScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cart = context.watch<CartService>();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('Your Cart')),
|
||||
body: cart.items.isEmpty
|
||||
? const Center(child: Text('Your cart is empty.'))
|
||||
: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: cart.items.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (context, index) {
|
||||
final item = cart.items[index];
|
||||
return ListTile(
|
||||
leading: SizedBox(
|
||||
width: 64,
|
||||
child:
|
||||
Image.network(item.product.imageUrl, fit: BoxFit.cover),
|
||||
),
|
||||
title: Text(item.product.name),
|
||||
subtitle:
|
||||
Text('\$${item.product.price.toStringAsFixed(2)} each'),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove_circle_outline),
|
||||
onPressed: item.quantity > 1
|
||||
? () => cart.updateQuantity(
|
||||
item.product.id,
|
||||
item.quantity - 1,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
Text('${item.quantity}'),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle_outline),
|
||||
onPressed: () => cart.updateQuantity(
|
||||
item.product.id,
|
||||
item.quantity + 1,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: () => cart.removeProduct(item.product.id),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
top: BorderSide(color: Colors.grey.shade300),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'Total: \$${cart.totalPrice.toStringAsFixed(2)}',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const CheckoutScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Proceed to Checkout'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user