91 lines
2.9 KiB
Dart
91 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import 'package:timetrack/features/projects/domain/project.dart';
|
|
import 'package:timetrack/features/timer/domain/timer_state.dart';
|
|
import 'package:timetrack/features/timer/domain/timer_notifier.dart';
|
|
|
|
class TimerControls extends ConsumerWidget {
|
|
const TimerControls({
|
|
super.key,
|
|
required this.state,
|
|
required this.selectedProject,
|
|
});
|
|
|
|
final TimerState state;
|
|
final Project? selectedProject;
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final notifier = ref.read(timerNotifierProvider.notifier);
|
|
final isRunning = state is TimerRunning;
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
if (!isRunning)
|
|
FilledButton.icon(
|
|
key: const Key('start_button'),
|
|
onPressed: selectedProject == null
|
|
? null
|
|
: () => notifier.start(selectedProject!),
|
|
icon: const Icon(Icons.play_arrow_rounded),
|
|
label: const Text('Start'),
|
|
style: FilledButton.styleFrom(
|
|
minimumSize: const Size(160, 56),
|
|
textStyle: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
)
|
|
else ...[
|
|
FilledButton.icon(
|
|
key: const Key('stop_button'),
|
|
onPressed: () => notifier.stop(),
|
|
icon: const Icon(Icons.stop_rounded),
|
|
label: const Text('Stop'),
|
|
style: FilledButton.styleFrom(
|
|
backgroundColor: colorScheme.error,
|
|
foregroundColor: colorScheme.onError,
|
|
minimumSize: const Size(160, 56),
|
|
textStyle: Theme.of(context).textTheme.titleMedium,
|
|
),
|
|
),
|
|
const SizedBox(height: 12),
|
|
TextButton.icon(
|
|
key: const Key('discard_button'),
|
|
onPressed: () => _confirmDiscard(context, notifier),
|
|
icon: const Icon(Icons.delete_outline),
|
|
label: const Text('Discard'),
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: colorScheme.onSurfaceVariant,
|
|
),
|
|
),
|
|
],
|
|
],
|
|
);
|
|
}
|
|
|
|
Future<void> _confirmDiscard(
|
|
BuildContext context,
|
|
TimerNotifier notifier,
|
|
) async {
|
|
final confirmed = await showDialog<bool>(
|
|
context: context,
|
|
builder: (ctx) => AlertDialog(
|
|
title: const Text('Discard entry?'),
|
|
content: const Text('The current time entry will be deleted.'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(ctx, false),
|
|
child: const Text('Cancel'),
|
|
),
|
|
FilledButton(
|
|
onPressed: () => Navigator.pop(ctx, true),
|
|
child: const Text('Discard'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
if (confirmed == true) await notifier.discard();
|
|
}
|
|
}
|