diff --git a/lib/main.dart b/lib/main.dart index 6e5d7a5..bc91015 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,6 +10,6 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - return MaterialApp(title: _title, home: MyHomePage()); + return const MaterialApp(title: _title, home: MyHomePage()); } } diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart index b17e524..48859bd 100644 --- a/lib/pages/main_page.dart +++ b/lib/pages/main_page.dart @@ -9,17 +9,17 @@ class MyHomePage extends StatefulWidget { const MyHomePage({super.key}); @override - _MyHomePageState createState() => _MyHomePageState(); + MyHomePageState createState() => MyHomePageState(); } -class _MyHomePageState extends State { +class MyHomePageState extends State { int _selectedIndex = 2; - static final List _widgetOptions = [ - const MoodPage(), - const SleepPage(), + static const List _widgetOptions = [ + MoodPage(), + SleepPage(), StopWatchTimerPage(), - const RelapsePage(), - const SettingsPage(), + RelapsePage(), + SettingsPage(), ]; void _onItemTapped(int index) { diff --git a/lib/pages/timer_page.dart b/lib/pages/timer_page.dart index ac9734e..899f862 100644 --- a/lib/pages/timer_page.dart +++ b/lib/pages/timer_page.dart @@ -3,34 +3,29 @@ import 'package:flutter/material.dart'; import 'package:smoke_cess_app/widgets/timer_button.dart'; class StopWatchTimerPage extends StatefulWidget { + const StopWatchTimerPage({super.key}); + @override - _StopWatchTimerPageState createState() => _StopWatchTimerPageState(); + StopWatchTimerPageState createState() => StopWatchTimerPageState(); } -class _StopWatchTimerPageState extends State { +class StopWatchTimerPageState extends State { static const countdownDuration = Duration(minutes: 1); - Duration duration = Duration(); + Duration duration = countdownDuration; Timer? timer; bool countDown = true; - @override - void initState() { - // TODO: implement initState - super.initState(); - reset(); - } - void reset() { if (countDown) { setState(() => duration = countdownDuration); } else { - setState(() => duration = Duration()); + setState(() => duration = const Duration()); } } void startTimer() { - timer = Timer.periodic(Duration(seconds: 1), (_) => addTime()); + timer = Timer.periodic(const Duration(seconds: 1), (_) => addTime()); } void addTime() { @@ -58,7 +53,7 @@ class _StopWatchTimerPageState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ buildTime(), - SizedBox( + const SizedBox( height: 80, ), buildButtons() @@ -71,11 +66,11 @@ class _StopWatchTimerPageState extends State { final minutes = twoDigits(duration.inMinutes.remainder(60)); final seconds = twoDigits(duration.inSeconds.remainder(60)); return Row(mainAxisAlignment: MainAxisAlignment.center, children: [ - SizedBox( + const SizedBox( width: 8, ), buildTimeCard(time: minutes, header: 'MINUTEN'), - SizedBox( + const SizedBox( width: 8, ), buildTimeCard(time: seconds, header: 'SEKUNDEN'), @@ -87,21 +82,21 @@ class _StopWatchTimerPageState extends State { mainAxisAlignment: MainAxisAlignment.center, children: [ Container( - padding: EdgeInsets.all(8), + padding: const EdgeInsets.all(8), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(20)), child: Text( time, - style: TextStyle( + style: const TextStyle( fontWeight: FontWeight.bold, color: Colors.black, fontSize: 50), ), ), - SizedBox( + const SizedBox( height: 24, ), - Text(header, style: TextStyle(color: Colors.black45)), + Text(header, style: const TextStyle(color: Colors.black45)), ], ); @@ -111,7 +106,7 @@ class _StopWatchTimerPageState extends State { return isRunning || isCompleted ? TimerButton( onClicked: stopTimer, - icon: Icon( + icon: const Icon( Icons.stop, size: 50, color: Colors.white, @@ -119,7 +114,7 @@ class _StopWatchTimerPageState extends State { color: Colors.red) : TimerButton( onClicked: startTimer, - icon: Icon( + icon: const Icon( Icons.play_arrow, size: 50, color: Colors.white, diff --git a/lib/widgets/timer_button.dart b/lib/widgets/timer_button.dart index f5fc6b2..75ebe06 100644 --- a/lib/widgets/timer_button.dart +++ b/lib/widgets/timer_button.dart @@ -12,16 +12,17 @@ class TimerButton extends StatelessWidget { required this.color}) : super(key: key); + @override Widget build(BuildContext context) { return Column( children: [ InkWell( + onTap: onClicked, child: CircleAvatar( backgroundColor: color, radius: 50, child: icon, ), - onTap: onClicked, ), ], );