can you enhance the cart system for example 
-the numbering in fooddetail scrren is not there one=ce added it show added with - and + connected to cart
-the cart should also have a detailed breakdown of food also overall make the cart view very advnced
-the home page has two cart button remove top one
overall make the whole app better and best and give me whole code and think about it best
"""
// models/food.dart
class Food {
  final String id;
  final String name;
  final double price;
  final String description;
  final String category;
  final List<String> images;
  final double? rating;

  Food({
    required this.id,
    required this.name,
    required this.price,
    required this.description,
    required this.category,
    required this.images,
    this.rating,
  });

  factory Food.fromJson(Map<String, dynamic> json) {
    return Food(
      id: json['_id'],
      name: json['name'],
      price: json['price'].toDouble(),
      description: json['description'],
      category: json['category'],
      images: List<String>.from(json['images']),
      rating: json['totalAverageRating']?.toDouble(),
    );
  }
}

"""
""
import 'package:flutter/foundation.dart';
import '../models/food.dart';

class CartProvider with ChangeNotifier {
  final Map<Food, int> _items = {};

  Map<Food, int> get items => _items;

  double get total => _items.entries
      .fold(0, (sum, item) => sum + (item.key.price * item.value));

  void addItem(Food food) {
    if (_items.containsKey(food)) {
      _items[food] = _items[food]! + 1;
    } else {
      _items[food] = 1;
    }
    notifyListeners();
  }

  void removeItem(Food food) {
    if (_items.containsKey(food)) {
      if (_items[food]! > 1) {
        _items[food] = _items[food]! - 1;
      } else {
        _items.remove(food);
      }
    }
    notifyListeners();
  }

  void clear() {
    _items.clear();
    notifyListeners();
  }
}

"""
"""
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';
import '../providers/cart_provider.dart';

class CartScreen extends StatelessWidget {
  const CartScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Cart')),
      body: Consumer<CartProvider>(
        builder: (context, cart, _) {
          if (cart.items.isEmpty) {
            return const Center(
              child: Text('Your cart is empty'),
            );
          }

          return ListView(
            padding: const EdgeInsets.all(16),
            children: [
              ...cart.items.entries.map(
                    (entry) => Card(
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Row(
                      children: [
                        ClipRRect(
                          borderRadius: BorderRadius.circular(4),
                          child: Image.network(
                            entry.key.images.first,
                            width: 80,
                            height: 80,
                            fit: BoxFit.cover,
                          ),
                        ),
                        const SizedBox(width: 16),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                entry.key.name,
                                style: const TextStyle(
                                  fontSize: 16,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                              Text(
                                '₹${entry.key.price.toStringAsFixed(2)}',
                                style: TextStyle(
                                  color: Theme.of(context).primaryColor,
                                ),
                              ),
                            ],
                          ),
                        ),
                        Row(
                          children: [
                            IconButton(
                              icon: const Icon(Icons.remove),
                              onPressed: () =>
                                  cart.removeItem(entry.key),
                            ),
                            Text(
                              entry.value.toString(),
                              style: const TextStyle(fontSize: 16),
                            ),
                            IconButton(
                              icon: const Icon(Icons.add),
                              onPressed: () =>
                                  cart.addItem(entry.key),
                            ),
                          ],
                        ),
                      ],
                    ),
                  ),
                ),
              ),
              const SizedBox(height: 16),
              Card(
                child: Padding(
                  padding: const EdgeInsets.all(16),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          const Text(
                            'Total:',
                            style: TextStyle(
                              fontSize: 18,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                          Text(
                            '₹${cart.total.toStringAsFixed(2)}',
                            style: TextStyle(
                              fontSize: 18,
                              fontWeight: FontWeight.bold,
                              color: Theme.of(context).primaryColor,
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ],
          );
        },
      ),
      bottomNavigationBar: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: ElevatedButton.icon(
            onPressed: () {
              final Uri phoneNumber = Uri.parse('tel:+1234567890'); // Replace with actual phone number
              launchUrl(phoneNumber);
            },
            icon: const Icon(Icons.phone),
            label: const Text('Call Restaurant'),
          ),
        ),
      ),
    );
  }
}
"""
"""
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/food.dart';
import '../providers/cart_provider.dart';
import '../services/food_service.dart';

class FoodDetailsScreen extends StatefulWidget {
  final Food food;
  const FoodDetailsScreen({super.key, required this.food});

  @override
  State<FoodDetailsScreen> createState() => _FoodDetailsScreenState();
}

class _FoodDetailsScreenState extends State<FoodDetailsScreen> {
  final _reviewController = TextEditingController();
  final _nameController = TextEditingController();
  bool _isLoading = false;
  bool _showReviewForm = false; // Ternary condition for showing review form
  List<dynamic> reviews = [];
  final FoodService _foodService = FoodService();

  @override
  void initState() {
    super.initState();
    _loadReviews();
  }

  Future<void> _loadReviews() async {
    try {
      setState(() => _isLoading = true);
      final fetchedReviews = await _foodService.getFoodReviews(widget.food.id);
      setState(() {
        reviews = fetchedReviews;
        _isLoading = false;
      });
    } catch (e) {
      setState(() => _isLoading = false);
      _showErrorSnackBar('Failed to load reviews');
    }
  }

  Future<void> _submitReview(double rating) async {
    if (_nameController.text.isEmpty || _reviewController.text.isEmpty) {
      _showErrorSnackBar('Please fill in all fields');
      return;
    }

    try {
      setState(() => _isLoading = true);
      await _foodService.submitReview(
        widget.food.id,
        rating,
        _nameController.text,
        _reviewController.text,
      );
      _nameController.clear();
      _reviewController.clear();
      setState(() => _showReviewForm = false); // Hide form after submission
      await _loadReviews();
      if (mounted) {
        ScaffoldMessenger.of(context).showSnackBar(
          const SnackBar(content: Text('Review submitted successfully')),
        );
      }
    } catch (e) {
      _showErrorSnackBar('Failed to submit review');
    } finally {
      setState(() => _isLoading = false);
    }
  }

  void _showErrorSnackBar(String message) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(message),
        backgroundColor: Colors.red,
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            expandedHeight: 300,
            pinned: true,
            floating: false,
            flexibleSpace: FlexibleSpaceBar(
              background: Stack(
                fit: StackFit.expand,
                children: [
                  Hero(
                    tag: 'food-${widget.food.id}',
                    child: Image.network(
                      widget.food.images.first,
                      fit: BoxFit.cover,
                      errorBuilder: (context, error, stackTrace) =>
                      const Center(child: Icon(Icons.error)),
                    ),
                  ),
                  const DecoratedBox(
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [Colors.transparent, Colors.black54],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          SliverToBoxAdapter(
            child: Padding(
              padding: const EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                        child: Text(
                          widget.food.name,
                          style: Theme.of(context).textTheme.headlineMedium,
                        ),
                      ),
                      if (widget.food.rating != null)
                        Container(
                          padding: const EdgeInsets.symmetric(
                            horizontal: 12,
                            vertical: 6,
                          ),
                          decoration: BoxDecoration(
                            color: Colors.green,
                            borderRadius: BorderRadius.circular(20),
                          ),
                          child: Row(
                            children: [
                              const Icon(Icons.star, size: 20, color: Colors.white),
                              const SizedBox(width: 4),
                              Text(
                                widget.food.rating!.toStringAsFixed(1),
                                style: const TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ],
                          ),
                        ),
                    ],
                  ),
                  const SizedBox(height: 8),
                  Text(
                    '₹${widget.food.price.toStringAsFixed(2)}',
                    style: TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.bold,
                      color: Theme.of(context).primaryColor,
                    ),
                  ),
                  const SizedBox(height: 16),
                  Text(
                    widget.food.description,
                    style: Theme.of(context).textTheme.bodyLarge,
                  ),
                  const SizedBox(height: 24),

                  // Reviews Section
                  Text(
                    'Reviews',
                    style: Theme.of(context).textTheme.titleLarge,
                  ),
                  const SizedBox(height: 16),

                  // Toggle "Write a Review" Button
                  ElevatedButton.icon(
                    onPressed: () {
                      setState(() => _showReviewForm = !_showReviewForm);
                    },
                    icon: const Icon(Icons.rate_review),
                    label: Text(_showReviewForm ? 'Cancel' : 'Write a Review'),
                    style: ElevatedButton.styleFrom(
                      backgroundColor: Colors.blueAccent,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(8),
                      ),
                    ),
                  ),

                  // Conditionally show the review form
                  if (_showReviewForm) ...[
                    const SizedBox(height: 8),
                    TextField(
                      controller: _nameController,
                      decoration: const InputDecoration(
                        labelText: 'Your Name',
                        border: OutlineInputBorder(),
                      ),
                    ),
                    const SizedBox(height: 8),
                    TextField(
                      controller: _reviewController,
                      decoration: const InputDecoration(
                        labelText: 'Write a review',
                        border: OutlineInputBorder(),
                      ),
                      maxLines: 3,
                    ),
                    const SizedBox(height: 8),
                    Row(
                      children: List.generate(5, (index) {
                        return IconButton(
                          icon: const Icon(Icons.star, color: Colors.amber),
                          onPressed: () => _submitReview(index + 1.0),
                        );
                      }),
                    ),
                  ],

                  const SizedBox(height: 16),

                  // Reviews List
                  if (_isLoading)
                    const Center(child: CircularProgressIndicator())
                  else
                    ListView.builder(
                      shrinkWrap: true,
                      physics: const NeverScrollableScrollPhysics(),
                      itemCount: reviews.length,
                      itemBuilder: (context, index) {
                        final review = reviews[index];
                        return Card(
                          margin: const EdgeInsets.symmetric(vertical: 4),
                          child: ListTile(
                            title: Text(review['name'] ?? 'Anonymous'),
                            subtitle: Text(review['description']),
                            trailing: Row(
                              mainAxisSize: MainAxisSize.min,
                              children: [
                                const Icon(Icons.star, color: Colors.amber),
                                Text(review['rating'].toString()),
                              ],
                            ),
                          ),
                        );
                      },
                    ),
                ],
              ),
            ),
          ),
        ],
      ),
      bottomNavigationBar: SafeArea(
        child: Padding(
          padding: const EdgeInsets.all(16),
          child: ElevatedButton(
            onPressed: () {
              context.read<CartProvider>().addItem(widget.food);
              ScaffoldMessenger.of(context).showSnackBar(
                const SnackBar(
                  content: Text('Added to cart'),
                  behavior: SnackBarBehavior.floating,
                ),
              );
            },
            style: ElevatedButton.styleFrom(
              padding: const EdgeInsets.symmetric(vertical: 16),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(8),
              ),
              backgroundColor: Colors.deepOrangeAccent, // More vibrant color
            ),
            child: const Text(
              'Add to Cart',
              style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
            ),
          ),
        ),
      ),
    );
  }

  @override
  void dispose() {
    _reviewController.dispose();
    _nameController.dispose();
    super.dispose();
  }
}
"""
"""
import 'package:flutter/material.dart';
import '../models/food.dart';
import '../widgets/food_card.dart';
import '../screens/cart_screen.dart';
import '../services/food_service.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with SingleTickerProviderStateMixin {
  List<Food> foods = [];
  String? filterCategory;
  bool isLoading = true;
  String? errorMessage;
  final FoodService _foodService = FoodService();

  late AnimationController _controller;
  late Animation<double> _animation;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(
      duration: const Duration(seconds: 1),
      vsync: this,
    );
    _animation = CurvedAnimation(parent: _controller, curve: Curves.easeInOut);

    Future.microtask(() => _fetchFoods());
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  Future<void> _fetchFoods() async {
    setState(() {
      isLoading = true;
      errorMessage = null;
    });

    try {
      final fetchedFoods = await _foodService.getFoods();
      setState(() {
        foods = fetchedFoods;
        isLoading = false;
        _controller.forward();  // Start the animation when data is loaded
      });
    } catch (e) {
      setState(() {
        errorMessage = 'Network error. Please check your connection.';
        isLoading = false;
      });
      _showErrorSnackBar('Network error. Please check your connection.');
    }
  }

  void _showErrorSnackBar(String message) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        content: Text(message),
        duration: const Duration(seconds: 4),
        action: SnackBarAction(
          label: 'Retry',
          onPressed: _fetchFoods,
        ),
      ),
    );
  }

  void _navigateToCart() {
    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => const CartScreen()),
    );
  }

  void _updateFilter(String? newFilter) {
    setState(() {
      filterCategory = newFilter;
    });
  }

  @override
  Widget build(BuildContext context) {
    final filteredFoods = filterCategory == null
        ? foods
        : foods.where((food) => food.category == filterCategory).toList();

    return Scaffold(
      appBar: AppBar(
        title: const Text('Restaurant Menu'),
        actions: [
          IconButton(
            icon: const Icon(Icons.shopping_cart),
            onPressed: _navigateToCart,
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _navigateToCart,
        backgroundColor: Colors.deepOrange,
        child: const Icon(Icons.shopping_cart),
      ),
      body: RefreshIndicator(
        onRefresh: _fetchFoods,
        child: Column(
          children: [
            _buildFilterChips(),
            Expanded(
              child: AnimatedOpacity(
                opacity: isLoading ? 0.5 : 1.0,
                duration: const Duration(milliseconds: 500),
                child: _buildContent(filteredFoods),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _buildFilterChips() {
    return Padding(
      padding: const EdgeInsets.all(8.0),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          FilterChip(
            label: const Text('All'),
            selected: filterCategory == null,
            onSelected: (_) => _updateFilter(null),
          ),
          FilterChip(
            label: const Text('Veg'),
            selected: filterCategory == 'veg',
            onSelected: (_) => _updateFilter('veg'),
          ),
          FilterChip(
            label: const Text('Non-Veg'),
            selected: filterCategory == 'non-veg',
            onSelected: (_) => _updateFilter('non-veg'),
          ),
        ],
      ),
    );
  }

  Widget _buildContent(List<Food> filteredFoods) {
    if (isLoading) {
      return const Center(child: CircularProgressIndicator());
    }

    if (filteredFoods.isEmpty) {
      return Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(errorMessage ?? 'No items found'),
            if (errorMessage != null)
              ElevatedButton(
                onPressed: _fetchFoods,
                child: const Text('Retry'),
              ),
          ],
        ),
      );
    }

    return GridView.builder(
      padding: const EdgeInsets.all(8),
      gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 2,
        childAspectRatio: 0.75,
        crossAxisSpacing: 10,
        mainAxisSpacing: 10,
      ),
      itemCount: filteredFoods.length,
      itemBuilder: (context, index) {
        final food = filteredFoods[index];
        return ScaleTransition(
          scale: _animation,
          child: FoodCard(food: food),
        );
      },
    );
  }
}
"""
"""
import 'package:flutter/material.dart';
import '../models/food.dart';
import '../screens/food_details_screen.dart';

class FoodCard extends StatelessWidget {
  final Food food;

  const FoodCard({super.key, required this.food});

  @override
  Widget build(BuildContext context) {
    return Card(
      elevation: 2,
      child: InkWell(
        onTap: () => Navigator.push(
          context,
          MaterialPageRoute(
            builder: (_) => FoodDetailsScreen(food: food),
          ),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: ClipRRect(
                borderRadius: const BorderRadius.vertical(top: Radius.circular(4)),
                child: Image.network(
                  food.images.first,
                  fit: BoxFit.cover,
                  width: double.infinity,
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    food.name,
                    style: const TextStyle(
                      fontSize: 16,
                      fontWeight: FontWeight.bold,
                    ),
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                  ),
                  const SizedBox(height: 4),
                  Row(
                    children: [
                      if (food.rating != null) ...[
                        Icon(
                          Icons.star,
                          size: 16,
                          color: Colors.amber,
                        ),
                        Text(
                          food.rating!.toStringAsFixed(1),
                          style: TextStyle(fontSize: 12),
                        ),
                        SizedBox(width: 8),
                      ],
                      Text(
                        '₹${food.price.toStringAsFixed(2)}',
                        style: TextStyle(
                          fontSize: 14,
                          fontWeight: FontWeight.bold,
                          color: Theme.of(context).primaryColor,
                        ),
                      ),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}