تحويل كود HTML إلى Flutter يتطلب تحويل هيكل الصفحة وعناصرها إلى ويدجتس Flutter المناسبة. بالإضافة إلى ذلك، سنحتاج إلى استخدام مكتبة font_awesome_flutter لدعم أيقونات Font Awesome المستخدمة في الكود الأصلي.
فيما يلي الشيفرة الكاملة لتحويل الصفحة المقدمة إلى تطبيق Flutter. يمكنك نسخ هذه الشيفرة إلى ملف main.dart في مشروع Flutter جديد وتشغيلها. تأكد من إضافة مكتبة font_awesome_flutter إلى ملف pubspec.yaml كما هو موضح أدناه.
1. إضافة المكتبات اللازمة
أولاً، تحتاج إلى إضافة مكتبة font_awesome_flutter إلى ملف pubspec.yaml:
dependencies:
flutter:
sdk: flutter
font_awesome_flutter: ^10.4.0
ثم قم بتشغيل الأمر التالي لتثبيت الحزمة:
flutter pub get
2. شيفرة Flutter الكاملة
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// تعيين اتجاه النص إلى اليمين ليتناسب مع اللغة العربية
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'د. محمد علي - إختصاص أسنان',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.indigo,
fontFamily: 'Segoe UI',
),
home: Directionality(
textDirection: TextDirection.rtl,
child: HomePage(),
),
);
}
}
class HomePage extends StatelessWidget {
// بيانات الحجوزات
final List<Booking> bookings = [
Booking(
name: 'محمد علي',
phone: '07712345678',
date: 'اليوم',
type: 'قلع سن',
status: 'في الإنتظار',
),
// يمكنك إضافة المزيد من الحجوزات هنا
];
// بيانات الخدمات
final List<Service> services = [
Service(
imageUrl: 'https://picsum.photos/400/250',
title: 'حشوة سن',
price: '250,000 د.ع',
),
Service(
imageUrl: 'https://picsum.photos/400/250',
title: 'قلع سن',
price: '15,000 د.ع',
),
// يمكنك إضافة المزيد من الخدمات هنا
];
@override
Widget build(BuildContext context) {
return Scaffold(
// استخدام SingleChildScrollView للسماح بالتمرير
body: SingleChildScrollView(
child: Column(
children: [
// رأس الصفحة
HeaderSection(),
// المحتوى الرئيسي
Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
// قسم الحجوزات النشطة
SectionTitle(title: 'الحجوزات النشطة'),
SizedBox(height: 10),
CardsContainer(bookings: bookings),
SizedBox(height: 40),
// قسم الخدمات
SectionTitle(title: 'الخدمات'),
SizedBox(height: 10),
ShopsContainer(services: services),
],
),
),
// تذييل الصفحة
FooterSection(),
],
),
),
);
}
}
class HeaderSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
children: [
// الخلفية مع تدرج لوني
Container(
height: 280,
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage('https://picsum.photos/1200/400'),
fit: BoxFit.cover,
),
),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
Colors.indigo.withOpacity(0.8),
Colors.indigo.withOpacity(0.8),
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
),
// محتوى الرأس
Positioned.fill(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 40),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'د. محمد علي',
style: TextStyle(
color: Colors.white,
fontSize: 32,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 10),
Text(
'إختصاص أسنان',
style: TextStyle(
color: Colors.white,
fontSize: 20,
),
),
SizedBox(height: 5),
Text(
'قطاع 28، شارع نعمة الريفي، مقابل مصرف الطيف الإسلامي الإهلي',
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
SizedBox(height: 5),
Text(
'من السبت إلى الخميس — من 4 مساءً إلى 12 مساءً',
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
Spacer(),
ElevatedButton.icon(
onPressed: () {
// إضافة وظيفة الزر هنا
},
icon: FaIcon(FontAwesomeIcons.calendarAlt, color: Colors.white),
label: Text('حجز موعد'),
style: ElevatedButton.styleFrom(
primary: Colors.deepOrange,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25),
),
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 10),
),
),
],
),
),
),
],
);
}
}
class SectionTitle extends StatelessWidget {
final String title;
const SectionTitle({required this.title});
@override
Widget build(BuildContext context) {
return Align(
alignment: Alignment.centerRight,
child: Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Colors.indigo.shade800, width: 2),
),
),
child: Text(
title,
style: TextStyle(
fontSize: 24,
color: Colors.indigo.shade800,
fontWeight: FontWeight.bold,
),
),
),
);
}
}
class CardsContainer extends StatelessWidget {
final List<Booking> bookings;
const CardsContainer({required this.bookings});
@override
Widget build(BuildContext context) {
return Wrap(
spacing: 20,
runSpacing: 20,
children: bookings.map((booking) => BookingCard(booking: booking)).toList(),
);
}
}
class BookingCard extends StatelessWidget {
final Booking booking;
const BookingCard({required this.booking});
Color getStatusColor(String status) {
switch (status) {
case 'في الإنتظار':
return Colors.orange;
case 'مؤكد':
return Colors.green;
case 'ملغي':
return Colors.red;
default:
return Colors.grey;
}
}
@override
Widget build(BuildContext context) {
return Card(
elevation: 4,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
child: Container(
width: 300,
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('اسم المراجع: ${booking.name}',
style: TextStyle(
color: Colors.indigo.shade800,
fontSize: 18,
fontWeight: FontWeight.bold,
)),
SizedBox(height: 10),
Text('رقم هاتف: ${booking.phone}', style: TextStyle(color: Colors.grey[700])),
SizedBox(height: 5),
Text('تاريخ الحجز: ${booking.date}', style: TextStyle(color: Colors.grey[700])),
SizedBox(height: 5),
Text('نوع الحجز: ${booking.type}', style: TextStyle(color: Colors.grey[700])),
SizedBox(height: 5),
Row(
children: [
Text('حالة الحجز: ', style: TextStyle(color: Colors.grey[700])),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
decoration: BoxDecoration(
color: getStatusColor(booking.status),
borderRadius: BorderRadius.circular(20),
),
child: Text(
booking.status,
style: TextStyle(color: Colors.white, fontSize: 14),
),
),
],
),
SizedBox(height: 15),
Row(
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () {
// إضافة وظيفة تعديل الحجز هنا
},
icon: FaIcon(FontAwesomeIcons.edit, size: 14),
label: Text('تعديل'),
style: ElevatedButton.styleFrom(
primary: Colors.amber,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
padding: EdgeInsets.symmetric(vertical: 10),
),
),
),
SizedBox(width: 10),
Expanded(
child: ElevatedButton.icon(
onPressed: () {
// إضافة وظيفة إلغاء الحجز هنا
},
icon: FaIcon(FontAwesomeIcons.trash, size: 14),
label: Text('إلغاء'),
style: ElevatedButton.styleFrom(
primary: Colors.red,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
padding: EdgeInsets.symmetric(vertical: 10),
),
),
),
],
),
],
),
),
);
}
}
class ShopsContainer extends StatelessWidget {
final List<Service> services;
const ShopsContainer({required this.services});
@override
Widget build(BuildContext context) {
return Wrap(
spacing: 20,
runSpacing: 20,
children: services.map((service) => ServiceCard(service: service)).toList(),
);
}
}
class ServiceCard extends StatelessWidget {
final Service service;
const ServiceCard({required this.service});
@override
Widget build(BuildContext context) {
return Container(
width: 300,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.black12,
blurRadius: 4,
spreadRadius: 2,
offset: Offset(0, 4),
),
],
),
child: Column(
children: [
// صورة الخدمة
ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(10)),
child: Image.network(
service.imageUrl,
height: 200,
width: double.infinity,
fit: BoxFit.cover,
),
),
// محتوى الخدمة
Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(service.title,
style: TextStyle(
color: Colors.indigo.shade800,
fontSize: 20,
fontWeight: FontWeight.bold,
)),
SizedBox(height: 10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
service.price,
style: TextStyle(
color: Colors.white,
fontSize: 16,
),
),
ElevatedButton.icon(
onPressed: () {
// إضافة وظيفة الحجز هنا
},
icon: FaIcon(FontAwesomeIcons.book, color: Colors.white, size: 14),
label: Text('حجز'),
style: ElevatedButton.styleFrom(
primary: Colors.indigo,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
padding: EdgeInsets.symmetric(horizontal: 15, vertical: 5),
),
),
],
),
],
),
),
],
),
);
}
}
class FooterSection extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
color: Colors.indigo.shade800,
width: double.infinity,
padding: EdgeInsets.symmetric(vertical: 15, horizontal: 10),
child: Text(
'© 2021-2024 د. محمد علي. جميع الحقوق محفوظة.',
style: TextStyle(color: Colors.white),
textAlign: TextAlign.center,
),
);
}
}
// نموذج بيانات للحجوزات
class Booking {
final String name;
final String phone;
final String date;
final String type;
final String status;
Booking({
required this.name,
required this.phone,
required this.date,
required this.type,
required this.status,
});
}
// نموذج بيانات للخدمات
class Service {
final String imageUrl;
final String title;
final String price;
Service({
required this.imageUrl,
required this.title,
required this.price,
});
}
شرح الشيفرة
-
التوجيه واللغة العربية: تم استخدام Directionality لضبط اتجاه النص إلى اليمين بما يتناسب مع اللغة العربية.
-
رأس الصفحة: تم إنشاء ويدجت HeaderSection يحتوي على صورة خلفية مع تدرج لوني، وعرض العنوان والمعلومات الأخرى بالإضافة إلى زر "حجز موعد" باستخدام أيقونات FontAwesome.
-
الأقسام الرئيسية:
- الحجوزات النشطة: تم إنشاء ويدجت
CardsContainer التي تعرض قائمة من الحجوزات باستخدام ويدجت BookingCard.
- الخدمات: تم إنشاء ويدجت
ShopsContainer التي تعرض قائمة من الخدمات باستخدام ويدجت ServiceCard.
-
بطاقات الحجوزات: ويدجت BookingCard تعرض تفاصيل الحجز مع أزرار للتعديل والإلغاء.
-
بطاقات الخدمات: ويدجت ServiceCard تعرض صورة الخدمة، عنوانها، سعرها وزر للحجز.
-
تذييل الصفحة: ويدجت FooterSection تعرض حقوق النشر.
-
نماذج البيانات: تم إنشاء كلاسين Booking و Service لنموذج بيانات الحجوزات والخدمات على التوالي.
ملاحظات إضافية
-
التجاوب: Flutter يقوم بشكل افتراضي بتوفير واجهات تجاوبية، ولكن قد تحتاج إلى ضبط بعض الأبعاد أو التخطيطات حسب حاجة تطبيقك على الشاشات الصغيرة.
-
الأيقونات: تأكد من أن مكتبة font_awesome_flutter مضافة بشكل صحيح في ملف pubspec.yaml وأنك تستوردها في الملف كما هو موضح.
-
الوظائف: في الشيفرة أعلاه، أزرار مثل "حجز موعد"، "تعديل"، و"إلغاء" لا تحتوي على وظائف فعلية. يجب عليك إضافة الوظائف المناسبة حسب الحاجة.
-
الصور: يتم تحميل الصور من الإنترنت باستخدام روابط https://picsum.photos. يمكنك استبدالها بروابط صورك الخاصة أو استخدام أصول محلية.
بهذه الطريقة، يمكنك تحويل صفحتك المصممة بـ HTML وCSS إلى تطبيق Flutter متكامل يدعم اللغة العربية ويوفر تجربة مستخدم مماثلة.