first commit

This commit is contained in:
Hamza-Ayed
2026-10-04 00:19:45 +03:00
commit 05f1c9ec6b
93 changed files with 10782 additions and 0 deletions
+113
View File
@@ -0,0 +1,113 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../models/workout.dart';
import '../services/database_service.dart';
import '../utils/formatters.dart';
/// شاشة سجل التمارين (Workout History Screen)
class HistoryScreen extends StatelessWidget {
const HistoryScreen({super.key});
@override
Widget build(BuildContext context) {
final db = Get.find<DatabaseService>();
return Scaffold(
appBar: AppBar(
title: const Text("سجل التمارين", style: TextStyle(fontWeight: FontWeight.bold)),
backgroundColor: Colors.transparent,
elevation: 0,
),
body: FutureBuilder<List<Workout>>(
future: db.getAllWorkouts(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (!snapshot.hasData || snapshot.data!.isEmpty) {
return _buildEmptyState();
}
final workouts = snapshot.data!;
return ListView.builder(
padding: const EdgeInsets.all(20),
itemCount: workouts.length,
itemBuilder: (context, index) {
final workout = workouts[index];
return _buildWorkoutCard(workout);
},
);
},
),
);
}
Widget _buildEmptyState() {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.history_toggle_off, size: 80, color: Colors.white.withOpacity(0.1)),
const SizedBox(height: 20),
const Text("لا توجد تمارين مسجلة بعد", style: TextStyle(color: Colors.grey)),
],
),
);
}
Widget _buildWorkoutCard(Workout workout) {
return Card(
margin: const EdgeInsets.only(bottom: 15),
child: InkWell(
onTap: () {
// الانتقال لتفاصيل التمرين (مستقبلاً)
},
borderRadius: BorderRadius.circular(16),
child: Padding(
padding: const EdgeInsets.all(15.0),
child: Row(
children: [
// أيقونة النوع
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: (workout.workoutType == WorkoutType.running ? Colors.orange : Colors.green).withOpacity(0.1),
shape: BoxShape.circle,
),
child: Icon(
workout.workoutType == WorkoutType.running ? Icons.directions_run : Icons.directions_walk,
color: workout.workoutType == WorkoutType.running ? Colors.orange : Colors.green,
),
),
const SizedBox(width: 15),
// البيانات الأساسية
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
Formatters.date(workout.createdAt),
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
),
Text(
"${Formatters.distanceKm(workout.distanceMeters)} كم • ${Formatters.time(workout.durationSeconds)}",
style: const TextStyle(color: Colors.grey, fontSize: 13),
),
],
),
),
// حالة المزامنة
Icon(
workout.syncStatus == SyncStatus.synced ? Icons.cloud_done : Icons.cloud_upload_outlined,
size: 18,
color: workout.syncStatus == SyncStatus.synced ? Colors.blue : Colors.orange,
),
const Icon(Icons.chevron_right, color: Colors.grey),
],
),
),
),
);
}
}
+250
View File
@@ -0,0 +1,250 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controllers/workout_controller.dart';
import '../models/workout.dart';
import '../utils/formatters.dart';
import '../services/sync_service.dart';
class HomeScreen extends StatelessWidget {
const HomeScreen({super.key});
@override
Widget build(BuildContext context) {
final workoutCtrl = Get.find<WorkoutController>();
final syncService = Get.find<SyncService>();
return Scaffold(
body: CustomScrollView(
slivers: [
// 1. شريط العنوان المخصص (Premium Header)
SliverAppBar(
expandedHeight: 200,
floating: false,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: const Text("Tracker Running",
style: TextStyle(fontWeight: FontWeight.w800)),
background: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFFFF5722), Color(0xFFE64A19)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: Center(
child: Icon(Icons.directions_run,
size: 80, color: Colors.white.withOpacity(0.3)),
),
),
),
actions: [
Obx(() => IconButton(
icon: Icon(
syncService.isOnline
? Icons.cloud_done
: Icons.cloud_off,
color:
syncService.isOnline ? Colors.white : Colors.red),
onPressed: () {},
)),
],
),
// 2. حالة المزامنة السريعة
SliverToBoxAdapter(
child: Obx(() => syncService.pendingCount > 0
? Container(
padding: const EdgeInsets.all(8),
color: Colors.orange.withOpacity(0.2),
child: Center(
child: Text(
"لديك ${syncService.pendingCount} تمارين بانتظار المزامنة..",
style:
const TextStyle(fontSize: 12, color: Colors.orange),
),
),
)
: const SizedBox.shrink()),
),
// 3. أزرار البدء السريع (Quick Actions)
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("ابدأ رحلتك اليوم",
style:
TextStyle(fontSize: 22, fontWeight: FontWeight.bold)),
const SizedBox(height: 15),
Row(
children: [
_buildStartCard(
title: "ركض",
icon: Icons.run_circle,
color: const Color(0xFFFF5722),
onTap: () =>
workoutCtrl.startWorkout(WorkoutType.running),
),
const SizedBox(width: 15),
_buildStartCard(
title: "مشي",
icon: Icons.directions_walk,
color: Colors.green,
onTap: () =>
workoutCtrl.startWorkout(WorkoutType.walking),
),
],
),
],
),
),
),
// 4. عرض حالة التمرين الحالي (إذا كان نشطاً)
SliverToBoxAdapter(
child: Obx(() => workoutCtrl.currentWorkout.value != null
? _buildActiveWorkoutCard(workoutCtrl)
: const SizedBox.shrink()),
),
// 5. قسم الإحصائيات أو التمرين الأخير
SliverToBoxAdapter(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 10),
child: Card(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text("آخر تمرين",
style: TextStyle(fontWeight: FontWeight.bold)),
Text("عرض الكل",
style: TextStyle(
color: Color(0xFFFF5722), fontSize: 12)),
],
),
const Divider(height: 30, color: Colors.white10),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildMiniStat("المسافة", "0.0 كم"),
_buildMiniStat("الوقت", "00:00"),
_buildMiniStat("السعرات", "0"),
],
),
],
),
),
),
),
),
],
),
);
}
Widget _buildStartCard(
{required String title,
required IconData icon,
required Color color,
required VoidCallback onTap}) {
return Expanded(
child: GestureDetector(
onTap: onTap,
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: color.withOpacity(0.3), width: 2),
),
child: Column(
children: [
Icon(icon, size: 40, color: color),
const SizedBox(height: 10),
Text(title,
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold, color: color)),
],
),
),
),
);
}
Widget _buildActiveWorkoutCard(WorkoutController ctrl) {
return Padding(
padding: const EdgeInsets.all(20.0),
child: Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
color: const Color(0xFFFF5722),
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
const Text("التمرين قيد التسجيل...",
style: TextStyle(
color: Colors.white, fontWeight: FontWeight.bold)),
const SizedBox(height: 15),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildWhiteStat("المسافة",
"${Formatters.distanceKm(ctrl.liveDistance.value)} كم"),
_buildWhiteStat(
"الوقت", Formatters.time(ctrl.elapsedSeconds.value)),
_buildWhiteStat(
"السرعة", Formatters.speedKmh(ctrl.liveSpeed.value)),
],
),
const SizedBox(height: 20),
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => ctrl.stopWorkout(),
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
foregroundColor: Colors.red),
child: const Text("إنهاء"),
),
),
],
)
],
),
),
);
}
Widget _buildMiniStat(String label, String value) {
return Column(
children: [
Text(label, style: const TextStyle(fontSize: 12, color: Colors.grey)),
Text(value,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
],
);
}
Widget _buildWhiteStat(String label, String value) {
return Column(
children: [
Text(label,
style: const TextStyle(fontSize: 12, color: Colors.white70)),
Text(value,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: Colors.white)),
],
);
}
}
+235
View File
@@ -0,0 +1,235 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import '../controllers/workout_controller.dart';
import '../utils/formatters.dart';
/// شاشة تتبع التمرين (Live Tracking Screen)
/// تعرض الخريطة، المسار، والإحصائيات الحية.
class TrackingScreen extends StatefulWidget {
const TrackingScreen({super.key});
@override
State<TrackingScreen> createState() => _TrackingScreenState();
}
class _TrackingScreenState extends State<TrackingScreen> {
final MapController _mapController = MapController();
bool _followUser = true;
late Worker _worker;
@override
void initState() {
super.initState();
final ctrl = Get.find<WorkoutController>();
_worker = ever(ctrl.liveCoordinates, (coords) {
if (_followUser && coords.isNotEmpty) {
try {
final center = LatLng(coords.last.latitude, coords.last.longitude);
_mapController.move(center, _mapController.camera.zoom);
} catch (_) {
// Map not fully initialized yet
}
}
});
}
@override
void dispose() {
_worker.dispose();
_mapController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final ctrl = Get.find<WorkoutController>();
return Scaffold(
body: Stack(
children: [
// 1. الخريطة (The Map)
Obx(() {
final coords = ctrl.liveCoordinates;
final center = coords.isNotEmpty
? LatLng(coords.last.latitude, coords.last.longitude)
: const LatLng(31.9454, 35.9284); // Amman default
return FlutterMap(
mapController: _mapController,
options: MapOptions(
initialCenter: center,
initialZoom: 16,
onPositionChanged: (pos, hasGesture) {
if (hasGesture) setState(() => _followUser = false);
},
),
children: [
TileLayer(
urlTemplate: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
userAgentPackageName: 'com.musadaq.running',
),
// رسم المسار (The Route Polyline)
PolylineLayer(
polylines: [
Polyline(
points: coords.map((c) => LatLng(c.latitude, c.longitude)).toList(),
strokeWidth: 5,
color: const Color(0xFFFF5722),
),
],
),
// موقع المستخدم الحالي (Current Location Marker)
if (coords.isNotEmpty)
MarkerLayer(
markers: [
Marker(
point: LatLng(coords.last.latitude, coords.last.longitude),
width: 40,
height: 40,
child: _buildLocationMarker(),
),
],
),
],
);
}),
// 2. لوحة الإحصائيات (Stats Overlay)
_buildTopStats(ctrl),
// 3. أزرار التحكم (Control Buttons)
_buildBottomControls(ctrl),
// 4. زر إعادة التمركز (Recenter Button)
if (!_followUser)
Positioned(
right: 20,
bottom: 150,
child: FloatingActionButton.small(
onPressed: () => setState(() => _followUser = true),
backgroundColor: Colors.white,
child: const Icon(Icons.my_location, color: Colors.black),
),
),
],
),
);
}
Widget _buildTopStats(WorkoutController ctrl) {
return Positioned(
top: 50,
left: 20,
right: 20,
child: Container(
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 10),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.8),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: Colors.white10),
),
child: Obx(() => Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildStatItem("الوقت", Formatters.time(ctrl.elapsedSeconds.value)),
_buildStatItem("المسافة", "${Formatters.distanceKm(ctrl.liveDistance.value)} كم"),
_buildStatItem("الوتيرة", Formatters.pace(ctrl.liveSpeed.value)),
],
)),
),
);
}
Widget _buildStatItem(String label, String value) {
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(label, style: const TextStyle(color: Colors.grey, fontSize: 12)),
Text(value, style: const TextStyle(color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold)),
],
);
}
Widget _buildBottomControls(WorkoutController ctrl) {
return Positioned(
bottom: 40,
left: 30,
right: 30,
child: Obx(() {
final workout = ctrl.currentWorkout.value;
if (workout == null) return const SizedBox.shrink();
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
// زر التوقف المؤقت / الاستئناف
_buildCircleButton(
onPressed: workout.isPaused ? ctrl.resumeWorkout : ctrl.pauseWorkout,
icon: workout.isPaused ? Icons.play_arrow : Icons.pause,
color: Colors.orange,
),
// زر الإنهاء (ضغطة مطولة لتجنب الخطأ)
GestureDetector(
onLongPress: () {
ctrl.stopWorkout();
Get.back();
},
child: _buildCircleButton(
onPressed: () {
Get.snackbar("تنبيه", "اضغط مطولاً على زر الإيقاف للإنهاء",
snackPosition: SnackPosition.BOTTOM, backgroundColor: Colors.white, colorText: Colors.black);
},
icon: Icons.stop,
color: Colors.red,
size: 80,
),
),
],
);
}),
);
}
Widget _buildCircleButton({required VoidCallback onPressed, required IconData icon, required Color color, double size = 60}) {
return Container(
width: size,
height: size,
decoration: BoxDecoration(
color: color,
shape: BoxShape.circle,
boxShadow: [BoxShadow(color: color.withOpacity(0.4), blurRadius: 10, spreadRadius: 2)],
),
child: IconButton(
icon: Icon(icon, color: Colors.white, size: size * 0.5),
onPressed: onPressed,
),
);
}
Widget _buildLocationMarker() {
return Stack(
alignment: Alignment.center,
children: [
Container(
width: 30,
height: 30,
decoration: BoxDecoration(
color: const Color(0xFFFF5722).withOpacity(0.2),
shape: BoxShape.circle,
),
),
Container(
width: 15,
height: 15,
decoration: const BoxDecoration(
color: Color(0xFFFF5722),
shape: BoxShape.circle,
border: Border.fromBorderSide(BorderSide(color: Colors.white, width: 2)),
),
),
],
);
}
}