first commit
This commit is contained in:
@@ -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),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user