73 lines
2.3 KiB
Dart
73 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:timetrack/features/entries/domain/entries_provider.dart';
|
|
|
|
class TodaySummaryCard extends ConsumerWidget {
|
|
const TodaySummaryCard({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final now = DateTime.now();
|
|
final todayStart = DateTime(now.year, now.month, now.day);
|
|
final todayEnd = todayStart.add(const Duration(days: 1));
|
|
|
|
final entriesAsync = ref.watch(
|
|
entriesByDateRangeProvider(rangeFrom: todayStart, rangeTo: todayEnd),
|
|
);
|
|
|
|
return entriesAsync.when(
|
|
data: (entries) {
|
|
final completed = entries.where((e) => e.endTime != null).toList();
|
|
final total = completed.fold<int>(
|
|
0,
|
|
(sum, e) => sum + (e.durationSeconds ?? 0),
|
|
);
|
|
final totalDuration = Duration(seconds: total);
|
|
|
|
return Card(
|
|
margin: const EdgeInsets.symmetric(horizontal: 24, vertical: 8),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
children: [
|
|
const Icon(Icons.today_outlined),
|
|
const SizedBox(width: 12),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'Today',
|
|
style: Theme.of(context).textTheme.labelMedium,
|
|
),
|
|
Text(
|
|
_formatDuration(totalDuration),
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
Text(
|
|
'${completed.length} entr${completed.length == 1 ? 'y' : 'ies'}',
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
},
|
|
loading: () => const SizedBox.shrink(),
|
|
error: (e, st) => const SizedBox.shrink(),
|
|
);
|
|
}
|
|
|
|
String _formatDuration(Duration d) {
|
|
final h = d.inHours;
|
|
final m = d.inMinutes % 60;
|
|
if (h > 0) return '${h}h ${m}m';
|
|
if (m > 0) return '${m}m';
|
|
return '0m';
|
|
}
|
|
}
|