2023-02-26 19:52:45 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:smoke_cess_app/providers/timer_provider.dart';
|
|
|
|
import 'package:smoke_cess_app/utils/timer_util.dart';
|
|
|
|
|
|
|
|
class TimerWidget extends StatelessWidget {
|
|
|
|
final Duration duration;
|
|
|
|
const TimerWidget({super.key, required this.duration});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
TimerProvider timerProvider = context.watch<TimerProvider>();
|
|
|
|
return Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(formatTime(duration.inSeconds - timerProvider.elapsedSeconds)),
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: () => timerProvider.started
|
|
|
|
? timerProvider.stopTimer()
|
|
|
|
: timerProvider.startTimer(duration),
|
|
|
|
child: Text(timerProvider.started ? 'Stop' : 'Start'))
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|