115 lines
3.8 KiB
Dart
115 lines
3.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:kettlebell_tracker/models/training_session.dart';
|
|
import 'package:kettlebell_tracker/providers/training_provider.dart';
|
|
import 'package:kettlebell_tracker/theme/app_theme.dart';
|
|
import 'package:kettlebell_tracker/widgets/custom_card.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class HistoryScreen extends ConsumerWidget {
|
|
const HistoryScreen({super.key});
|
|
|
|
String _formatDuration(int totalSeconds) {
|
|
final duration = Duration(seconds: totalSeconds);
|
|
final minutes = duration.inMinutes.remainder(60).toString().padLeft(2, '0');
|
|
final seconds = duration.inSeconds.remainder(60).toString().padLeft(2, '0');
|
|
return '$minutes:$seconds';
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final historyAsyncValue = ref.watch(historyProvider);
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Trainingshistorie'),
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.refresh),
|
|
onPressed: () => ref.refresh(historyProvider),
|
|
),
|
|
],
|
|
),
|
|
body: historyAsyncValue.when(
|
|
data: (history) {
|
|
if (history.isEmpty) {
|
|
return const Center(
|
|
child: Text(
|
|
'Noch keine Trainingsdaten vorhanden.',
|
|
style: TextStyle(color: AppTheme.oneDarkTextWeak, fontSize: 16),
|
|
),
|
|
);
|
|
}
|
|
return ListView.builder(
|
|
padding: const EdgeInsets.all(8.0),
|
|
itemCount: history.length,
|
|
itemBuilder: (context, index) {
|
|
final session = history[index];
|
|
return HistoryItemCard(
|
|
session: session, formatDuration: _formatDuration);
|
|
},
|
|
);
|
|
},
|
|
loading: () => const Center(child: CircularProgressIndicator()),
|
|
error: (err, stack) => Center(child: Text('Fehler beim Laden: $err')),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class HistoryItemCard extends StatelessWidget {
|
|
const HistoryItemCard({
|
|
super.key,
|
|
required this.session,
|
|
required this.formatDuration,
|
|
});
|
|
|
|
final TrainingSession session;
|
|
final String Function(int) formatDuration;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
return CustomCard(
|
|
margin: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 8.0),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(DateFormat('dd.MM.yyyy HH:mm').format(session.date),
|
|
style: theme.textTheme.titleMedium?.copyWith(
|
|
color: AppTheme.oneDarkPrimary, fontWeight: FontWeight.bold)),
|
|
const Divider(color: AppTheme.oneDarkTextWeak, height: 20),
|
|
_buildInfoRow(Icons.repeat, 'Sätze: ${session.sets}'),
|
|
_buildInfoRow(Icons.fitness_center,
|
|
'Kettlebells: ${session.weightLeft}kg / ${session.weightRight}kg'),
|
|
_buildInfoRow(Icons.format_list_numbered,
|
|
'Reps pro Satz: ${session.repsPerSet}'),
|
|
_buildInfoRow(
|
|
Icons.timer, 'Dauer: ${formatDuration(session.duration)}'),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildInfoRow(IconData icon, String text, {bool isNote = false}) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
|
child: Row(
|
|
children: [
|
|
Icon(icon, size: 18, color: AppTheme.oneDarkTextWeak),
|
|
const SizedBox(width: 8),
|
|
Expanded(
|
|
child: Text(
|
|
text,
|
|
style: TextStyle(
|
|
fontSize: 15,
|
|
color: isNote ? AppTheme.oneDarkTextWeak : AppTheme.oneDarkText,
|
|
fontStyle: isNote ? FontStyle.italic : FontStyle.normal,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|