From ba1a6e37e7558f33d5523e10ee7306169ef0b986 Mon Sep 17 00:00:00 2001 From: Crondung <1922635@stud.hs-mannheim.de> Date: Tue, 14 Feb 2023 14:02:26 +0100 Subject: [PATCH] added structure with navbar, changed icons --- lib/main.dart | 11 +- lib/pages/main_page.dart | 62 +++++++++ lib/pages/mood_page.dart | 10 ++ lib/pages/relapse_page.dart | 10 ++ lib/pages/settings_page.dart | 10 ++ lib/pages/sleep_page.dart | 10 ++ lib/pages/timer_page.dart | 129 +++++++++++++++++ lib/screens/stopwatch_timer | 130 ------------------ .../{timer_button => timer_button.dart} | 13 +- 9 files changed, 242 insertions(+), 143 deletions(-) create mode 100644 lib/pages/main_page.dart create mode 100644 lib/pages/mood_page.dart create mode 100644 lib/pages/relapse_page.dart create mode 100644 lib/pages/settings_page.dart create mode 100644 lib/pages/sleep_page.dart create mode 100644 lib/pages/timer_page.dart delete mode 100644 lib/screens/stopwatch_timer rename lib/widgets/{timer_button => timer_button.dart} (62%) diff --git a/lib/main.dart b/lib/main.dart index 9693f52..6e5d7a5 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,5 +1,5 @@ import 'package:flutter/material.dart'; -import 'package:smoke_cess_app/screens/stopwatch_timer'; +import 'package:smoke_cess_app/pages/main_page.dart'; void main() => runApp(const MyApp()); @@ -10,13 +10,6 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - return MaterialApp( - title: _title, - home: Scaffold( - appBar: AppBar( - title: const Text(_title), - ), - body: StopWatchTimerPage()), - ); + return MaterialApp(title: _title, home: MyHomePage()); } } diff --git a/lib/pages/main_page.dart b/lib/pages/main_page.dart new file mode 100644 index 0000000..b17e524 --- /dev/null +++ b/lib/pages/main_page.dart @@ -0,0 +1,62 @@ +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/pages/mood_page.dart'; +import 'package:smoke_cess_app/pages/relapse_page.dart'; +import 'package:smoke_cess_app/pages/settings_page.dart'; +import 'package:smoke_cess_app/pages/sleep_page.dart'; +import 'package:smoke_cess_app/pages/timer_page.dart'; + +class MyHomePage extends StatefulWidget { + const MyHomePage({super.key}); + + @override + _MyHomePageState createState() => _MyHomePageState(); +} + +class _MyHomePageState extends State { + int _selectedIndex = 2; + static final List _widgetOptions = [ + const MoodPage(), + const SleepPage(), + StopWatchTimerPage(), + const RelapsePage(), + const SettingsPage(), + ]; + + void _onItemTapped(int index) { + setState(() => _selectedIndex = index); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(title: const Text('ZI Rauchentwöhnung')), + body: _widgetOptions.elementAt(_selectedIndex), + bottomNavigationBar: NavigationBar( + onDestinationSelected: _onItemTapped, + selectedIndex: _selectedIndex, + destinations: const [ + NavigationDestination( + icon: Icon(Icons.mood_outlined, color: Colors.black), + label: 'Stimmung'), + NavigationDestination( + icon: Icon(Icons.bedtime_outlined, color: Colors.black), + label: 'Schlaf'), + NavigationDestination( + icon: Icon( + Icons.timer_outlined, + color: Colors.black, + ), + label: 'Timer'), + NavigationDestination( + icon: Icon(Icons.smoke_free_outlined, color: Colors.black), + label: 'Rückfall'), + NavigationDestination( + icon: Icon(Icons.settings, color: Colors.black), + label: 'Settings'), + ], + + //onTap: _onItemTapped, + ), + ); + } +} diff --git a/lib/pages/mood_page.dart b/lib/pages/mood_page.dart new file mode 100644 index 0000000..a8c4a4e --- /dev/null +++ b/lib/pages/mood_page.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class MoodPage extends StatelessWidget { + const MoodPage({super.key}); + + @override + Widget build(BuildContext context) { + return const Center(child: Text('Hier Fragen wir die Stimmung ab')); + } +} diff --git a/lib/pages/relapse_page.dart b/lib/pages/relapse_page.dart new file mode 100644 index 0000000..7710e10 --- /dev/null +++ b/lib/pages/relapse_page.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class RelapsePage extends StatelessWidget { + const RelapsePage({super.key}); + + @override + Widget build(BuildContext context) { + return const Center(child: Text('Hier werden Rückfälle dokumentiert')); + } +} diff --git a/lib/pages/settings_page.dart b/lib/pages/settings_page.dart new file mode 100644 index 0000000..899b163 --- /dev/null +++ b/lib/pages/settings_page.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class SettingsPage extends StatelessWidget { + const SettingsPage({super.key}); + + @override + Widget build(BuildContext context) { + return const Center(child: Text('Hier können Settings eingestellt werden')); + } +} diff --git a/lib/pages/sleep_page.dart b/lib/pages/sleep_page.dart new file mode 100644 index 0000000..281c580 --- /dev/null +++ b/lib/pages/sleep_page.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class SleepPage extends StatelessWidget { + const SleepPage({super.key}); + + @override + Widget build(BuildContext context) { + return const Center(child: Text('Hier wird Schlafqualität abgefragt')); + } +} diff --git a/lib/pages/timer_page.dart b/lib/pages/timer_page.dart new file mode 100644 index 0000000..ac9734e --- /dev/null +++ b/lib/pages/timer_page.dart @@ -0,0 +1,129 @@ +import 'dart:async'; +import 'package:flutter/material.dart'; +import 'package:smoke_cess_app/widgets/timer_button.dart'; + +class StopWatchTimerPage extends StatefulWidget { + @override + _StopWatchTimerPageState createState() => _StopWatchTimerPageState(); +} + +class _StopWatchTimerPageState extends State { + static const countdownDuration = Duration(minutes: 1); + Duration duration = Duration(); + 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()); + } + } + + void startTimer() { + timer = Timer.periodic(Duration(seconds: 1), (_) => addTime()); + } + + void addTime() { + final addSeconds = countDown ? -1 : 1; + setState(() { + final seconds = duration.inSeconds + addSeconds; + if (seconds < 0) { + timer?.cancel(); + } else { + duration = Duration(seconds: seconds); + } + }); + } + + void stopTimer({bool resets = true}) { + if (resets) { + reset(); + } + setState(() => timer?.cancel()); + } + + @override + Widget build(BuildContext context) => Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + buildTime(), + SizedBox( + height: 80, + ), + buildButtons() + ], + ), + ); + + Widget buildTime() { + String twoDigits(int n) => n.toString().padLeft(2, '0'); + final minutes = twoDigits(duration.inMinutes.remainder(60)); + final seconds = twoDigits(duration.inSeconds.remainder(60)); + return Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + SizedBox( + width: 8, + ), + buildTimeCard(time: minutes, header: 'MINUTEN'), + SizedBox( + width: 8, + ), + buildTimeCard(time: seconds, header: 'SEKUNDEN'), + ]); + } + + Widget buildTimeCard({required String time, required String header}) => + Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + padding: EdgeInsets.all(8), + decoration: BoxDecoration( + color: Colors.white, borderRadius: BorderRadius.circular(20)), + child: Text( + time, + style: TextStyle( + fontWeight: FontWeight.bold, + color: Colors.black, + fontSize: 50), + ), + ), + SizedBox( + height: 24, + ), + Text(header, style: TextStyle(color: Colors.black45)), + ], + ); + + Widget buildButtons() { + final isRunning = timer == null ? false : timer!.isActive; + final isCompleted = duration.inSeconds == 0; + return isRunning || isCompleted + ? TimerButton( + onClicked: stopTimer, + icon: Icon( + Icons.stop, + size: 50, + color: Colors.white, + ), + color: Colors.red) + : TimerButton( + onClicked: startTimer, + icon: Icon( + Icons.play_arrow, + size: 50, + color: Colors.white, + ), + color: Colors.green); + } +} diff --git a/lib/screens/stopwatch_timer b/lib/screens/stopwatch_timer deleted file mode 100644 index 1e5c5bd..0000000 --- a/lib/screens/stopwatch_timer +++ /dev/null @@ -1,130 +0,0 @@ -import 'dart:async'; -import 'package:flutter/material.dart'; -import 'package:smoke_cess_app/widgets/timer_button'; - -class StopWatchTimerPage extends StatefulWidget { - @override - _StopWatchTimerPageState createState() => _StopWatchTimerPageState(); -} - - -class _StopWatchTimerPageState extends State { - static const countdownDuration = Duration(minutes: 1); - Duration duration = Duration(); - 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()); - } - } - - void startTimer(){ - timer = Timer.periodic(Duration(seconds: 1),(_) => addTime()); - } - - void addTime(){ - final addSeconds = countDown ? -1 : 1; - setState(() { - final seconds = duration.inSeconds + addSeconds; - if (seconds < 0){ - timer?.cancel(); - } else{ - duration = Duration(seconds: seconds); - - } - }); - } - - void stopTimer({bool resets = true}){ - if (resets){ - reset(); - } - setState(() => timer?.cancel()); - } - - @override - Widget build(BuildContext context) => Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - buildTime(), - SizedBox(height: 80,), - buildButtons() - ], - ), - ); - - Widget buildTime(){ - String twoDigits(int n) => n.toString().padLeft(2,'0'); - final minutes =twoDigits(duration.inMinutes.remainder(60)); - final seconds =twoDigits(duration.inSeconds.remainder(60)); - return Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - - SizedBox(width: 8,), - buildTimeCard(time: minutes, header:'MINUTES'), - SizedBox(width: 8,), - buildTimeCard(time: seconds, header:'SECONDS'), - ] - ); - } - - Widget buildTimeCard({required String time, required String header}) => - Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - padding: EdgeInsets.all(8), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(20) - ), - child: Text( - time, style: TextStyle(fontWeight: FontWeight.bold, - color: Colors.black,fontSize: 50),), - ), - SizedBox(height: 24,), - Text(header,style: TextStyle(color: Colors.black45)), - ], - ); - - Widget buildButtons(){ - final isRunning = timer == null? false: timer!.isActive; - final isCompleted = duration.inSeconds == 0; - return isRunning || isCompleted - ? - TimerButton( - onClicked: stopTimer, - icon: Icon( - Icons.stop, - size: 50, - color: Colors.white, - ), - color: Colors.red) - : - TimerButton( - onClicked: startTimer, - icon: Icon( - Icons.play_arrow, - size: 50, - color: Colors.white, - ), - color: Colors.green); - - } -} \ No newline at end of file diff --git a/lib/widgets/timer_button b/lib/widgets/timer_button.dart similarity index 62% rename from lib/widgets/timer_button rename to lib/widgets/timer_button.dart index cc0943c..f5fc6b2 100644 --- a/lib/widgets/timer_button +++ b/lib/widgets/timer_button.dart @@ -1,13 +1,18 @@ import 'package:flutter/material.dart'; class TimerButton extends StatelessWidget { -final VoidCallback onClicked; + final VoidCallback onClicked; final Icon icon; final Color color; - const TimerButton({Key? key, required this.onClicked, required this.icon, required this.color}): super(key: key); + const TimerButton( + {Key? key, + required this.onClicked, + required this.icon, + required this.color}) + : super(key: key); - Widget build(BuildContext context) { + Widget build(BuildContext context) { return Column( children: [ InkWell( @@ -21,4 +26,4 @@ final VoidCallback onClicked; ], ); } -} \ No newline at end of file +}