ممتاز! سأجهز لك كود أولي (Prototype) باستخدام Flutter لواجهة تطبيق بيع ملابس بسيط، بناءً على متطلباتك:
- التطبيق لك فقط (لا يوجد تسجيل دخول أو مستخدمين آخرين)
- عرض منتجات ملابس
- إمكانية الشراء الفوري (بدون دفع حقيقي)
- نظام تقييم للمنتجات
- تتبع حالة الشحنة
- تصميم عصري وبسيط
سأبدأ بكتابة كود أولي لعدة شاشات رئيسية:
- الصفحة الرئيسية (قائمة المنتجات)
- صفحة تفاصيل المنتج (مع التقييم)
- سلة المشتريات
- صفحة تتبع الشحنة
الكود الأولي (Flutter)
يمكنك نسخ الكود وتجربته مباشرة في مشروع Flutter جديد.
1. ملف main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyClothesApp());
}
class MyClothesApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'My Closet',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
// نموذج بيانات منتج
class Product {
final String name;
final String image;
final double price;
double rating;
String status; // حالة الشحنة
Product({
required this.name,
required this.image,
required this.price,
this.rating = 4.0,
this.status = "قيد التجهيز",
});
}
// قائمة منتجات تجريبية
List<Product> products = [
Product(
name: "تيشيرت أبيض",
image: "https://images.pexels.com/photos/1004016/pexels-photo-1004016.jpeg",
price: 80.0,
),
Product(
name: "بنطال جينز",
image: "https://images.pexels.com/photos/2983464/pexels-photo-2983464.jpeg",
price: 120.0,
),
Product(
name: "فستان صيفي",
image: "https://images.pexels.com/photos/1488463/pexels-photo-1488463.jpeg",
price: 150.0,
),
];
List<Product> cart = [];
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('My Closet'),
actions: [
IconButton(
icon: Icon(Icons.shopping_cart),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (_) => CartPage()),
);
},
),
],
),
body: ListView.builder(
itemCount: products.length,
itemBuilder: (context, index) {
final product = products[index];
return Card(
margin: EdgeInsets.all(10),
child: ListTile(
leading: Image.network(product.image, width: 60, fit: BoxFit.cover),
title: Text(product.name),
subtitle: Text('${product.price} ريال'),
trailing: Icon(Icons.arrow_forward_ios),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => ProductDetailsPage(product: product),
),
);
},
),
);
},
),
);
}
}
class ProductDetailsPage extends StatefulWidget {
final Product product;
ProductDetailsPage({required this.product});
@override
_ProductDetailsPageState createState() => _ProductDetailsPageState();
}
class _ProductDetailsPageState extends State<ProductDetailsPage> {
double _currentRating = 0;
@override
void initState() {
super.initState();
_currentRating = widget.product.rating;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.product.name),
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Center(
child: Image.network(widget.product.image, height: 200),
),
SizedBox(height: 20),
Text(widget.product.name, style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
SizedBox(height: 10),
Text('${widget.product.price} ريال', style: TextStyle(fontSize: 18, color: Colors.blue)),
SizedBox(height: 10),
Row(
children: [
Text('التقييم: ', style: TextStyle(fontSize: 16)),
Icon(Icons.star, color: Colors.amber),
Text('${widget.product.rating.toStringAsFixed(1)}'),
],
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
setState(() {
cart.add(widget.product);
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('تمت إضافة المنتج إلى السلة!')),
);
},
child: Text('أضف إلى السلة'),
),
SizedBox(height: 20),
Text('قيّم المنتج:', style: TextStyle(fontSize: 16)),
Slider(
value: _currentRating,
min: 1,
max: 5,
divisions: 4,
label: _currentRating.toStringAsFixed(1),
onChanged: (value) {
setState(() {
_currentRating = value;
widget.product.rating = value;
});
},
),
SizedBox(height: 20),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => TrackingPage(product: widget.product),
),
);
},
child: Text('تتبع الشحنة'),
),
],
),
),
);
}
}
class CartPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
double total = cart.fold(0, (sum, item) => sum + item.price);
return Scaffold(
appBar: AppBar(
title: Text('سلة المشتريات'),
),
body: cart.isEmpty
? Center(child: Text('السلة فارغة'))
: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: cart.length,
itemBuilder: (context, index) {
final product = cart[index];
return ListTile(
leading: Image.network(product.image, width: 50),
title: Text(product.name),
subtitle: Text('${product.price} ريال'),
trailing: IconButton(
icon: Icon(Icons.delete),
onPressed: () {
cart.removeAt(index);
(context as Element).reassemble();
},
),
);
},
),
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('الإجمالي: $total ريال', style: TextStyle(fontSize: 18)),
ElevatedButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('تم إتمام الطلب!')),
);
cart.clear();
(context as Element).reassemble();
},
child: Text('إتمام الشراء'),
),
],
),
),
],
),
);
}
}
class TrackingPage extends StatelessWidget {
final Product product;
TrackingPage({required this.product});
@override
Widget build(BuildContext context) {
// حالات الشحنة التجريبية
List<String> statuses = [
"قيد التجهيز",
"تم الشحن",
"في الطريق",
"تم التسليم"
];
int currentStatus = statuses.indexOf(product.status);
return Scaffold(
appBar: AppBar(
title: Text('تتبع الشحنة'),
),
body: Padding(
padding: const EdgeInsets.all(24.0),
child: Column(
children: [
Text(product.name, style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold)),
SizedBox(height: 20),
Image.network(product.image, height: 120),
SizedBox(height: 30),
Text('حالة الشحنة:', style: TextStyle(fontSize: 18)),
SizedBox(height: 10),
Column(
children: List.generate(statuses.length, (index) {
return ListTile(
leading: Icon(
index <= currentStatus ? Icons.check_circle : Icons.radio_button_unchecked,
color: index <= currentStatus ? Colors.green : Colors.grey,
),
title: Text(statuses[index]),
);
}),
),
SizedBox(height: 30),
ElevatedButton(
onPressed: () {
// تحديث حالة الشحنة (تجريبي)
if (currentStatus < statuses.length - 1) {
product.status = statuses[currentStatus + 1];
(context as Element).reassemble();
}
},
child: Text('تحديث حالة الشحنة'),
),
],
),
),
);
}
}