Kodax

متجر إلكتروني — تحدي Dart

عربة تسوق: addItem تزيد الكمية إذا كان المنتج موجوداً وإلا تضيفه، و removeItem تحذفه، و totalPrice مجموع السعر × الكمية، و itemCount مجموع الكميات. (يُفحص الكود بنيوياً.)

// نموذج المنتج
class Product {
  final String id;
  final String name;
  final double price;
  int quantity;
  Product({required this.id, required this.name, required this.price, this.quantity = 1});
}

// عربة التسوق
class Cart {
  List<Product> items = [];

  // إضافة منتج للعربة
  void addItem(Product product) {
    // أكمل
  }

  // حذف منتج من العربة
  void removeItem(String productId) {
    // أكمل
  }

  // حساب المجموع الكلي
  double get totalPrice {
    // أكمل
    return 0.0;
  }

  // عدد العناصر
  int get itemCount {
    // أكمل
    return 0;
  }

  // تطبيق خصم بنسبة معينة
  double applyDiscount(double percentage) {
    // أكمل
    return 0.0;
  }
}

حل هذا التحدي يرتبط بفتح دورة «Flutter المتقدم» بحسابك.

ابدأ الحل