From 3338a4b0cab6aa00458288980956afec714b6192 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Sun, 21 Apr 2024 12:55:55 +0300 Subject: [PATCH] Fixing broken functionality --- lib/presentation/atoms/text_atom.dart | 17 +++--- lib/presentation/atoms/timer_atom.dart | 7 ++- .../organisms/timer_molecule.dart | 54 +++++++++---------- lib/presentation/pages/home_page.dart | 26 +++++---- lib/presentation/pages/intro_page.dart | 46 +++++++++++++++- 5 files changed, 102 insertions(+), 48 deletions(-) diff --git a/lib/presentation/atoms/text_atom.dart b/lib/presentation/atoms/text_atom.dart index 5401649..8e860c1 100644 --- a/lib/presentation/atoms/text_atom.dart +++ b/lib/presentation/atoms/text_atom.dart @@ -11,7 +11,7 @@ class TextAtom extends StatelessWidget { this.maxLines, this.translationArgs, this.translate = true, - this.veriant = TextVeriant.regular, + this.variant = TextVariant.regular, }); final String text; @@ -21,7 +21,7 @@ class TextAtom extends StatelessWidget { final int? maxLines; final List? translationArgs; final bool translate; - final TextVeriant veriant; + final TextVariant variant; @override Widget build(BuildContext context) { @@ -29,12 +29,14 @@ class TextAtom extends StatelessWidget { final TextTheme textTheme = themeData.textTheme; TextStyle? tempStyle = style; - switch (veriant) { - case TextVeriant.regular: + switch (variant) { + case TextVariant.regular: break; - case TextVeriant.smallTitle: + case TextVariant.smallTitle: tempStyle = textTheme.titleLarge; - case TextVeriant.medium: + case TextVariant.title: + tempStyle = textTheme.headlineMedium; + case TextVariant.medium: tempStyle = textTheme.bodyMedium; } @@ -48,11 +50,12 @@ class TextAtom extends StatelessWidget { } } -enum TextVeriant { +enum TextVariant { smallTitle, /// define out side, trying to deprecate regular, medium, + title, ; } diff --git a/lib/presentation/atoms/timer_atom.dart b/lib/presentation/atoms/timer_atom.dart index 6d91c97..32e0952 100644 --- a/lib/presentation/atoms/timer_atom.dart +++ b/lib/presentation/atoms/timer_atom.dart @@ -15,6 +15,9 @@ class TimerAtom extends StatelessWidget { @override Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + final ColorScheme colorScheme = themeData.colorScheme; + return CircularCountDownTimer( duration: timer.inSeconds, controller: controller, @@ -24,9 +27,9 @@ class TimerAtom extends StatelessWidget { fillColor: Colors.purpleAccent[100]!, strokeWidth: 20.0, strokeCap: StrokeCap.round, - textStyle: const TextStyle( + textStyle: TextStyle( fontSize: 33.0, - color: Colors.white, + color: colorScheme.onBackground, fontWeight: FontWeight.bold, ), textFormat: CountdownTextFormat.S, diff --git a/lib/presentation/organisms/timer_molecule.dart b/lib/presentation/organisms/timer_molecule.dart index d2cbc1a..43aa567 100644 --- a/lib/presentation/organisms/timer_molecule.dart +++ b/lib/presentation/organisms/timer_molecule.dart @@ -12,35 +12,33 @@ class TimerMolecule extends StatelessWidget { @override Widget build(BuildContext context) { - return Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Center( - child: TimerAtom( - controller, - duration, - onComplete, - ), - ), - const SeparatorAtom(), - Row( - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - children: [ - ButtonAtom( - variant: ButtonVariant.primary, - onPressed: controller.resume, - text: 'Continue', - ), - ButtonAtom( - variant: ButtonVariant.secondary, - onPressed: controller.pause, - text: 'Pause', - ), - ], + return Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Center( + child: TimerAtom( + controller, + duration, + onComplete, ), - ], - ), + ), + const SeparatorAtom(), + Column( + children: [ + ButtonAtom( + variant: ButtonVariant.primary, + onPressed: controller.resume, + text: 'Continue', + ), + const SeparatorAtom(), + ButtonAtom( + variant: ButtonVariant.secondary, + onPressed: controller.pause, + text: 'Pause', + ), + ], + ), + ], ); } } diff --git a/lib/presentation/pages/home_page.dart b/lib/presentation/pages/home_page.dart index 3ef8bbe..5c8b071 100644 --- a/lib/presentation/pages/home_page.dart +++ b/lib/presentation/pages/home_page.dart @@ -37,7 +37,10 @@ class _HomePageState extends State { return Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - const TextAtom('Study'), + const TextAtom( + 'Study Timer', + variant: TextVariant.smallTitle, + ), TimerMolecule( onTimerComplete, StudyTypeAbstract.instance!.energy.duration, @@ -81,14 +84,19 @@ class _HomePageState extends State { @override Widget build(BuildContext context) { return Scaffold( - body: Column( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - const TextAtom('Maximize Study Efficiency'), - Expanded( - child: stateWidget(), - ), - ], + body: SafeArea( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + const TextAtom( + 'Maximize Study Efficiency', + variant: TextVariant.title, + ), + Expanded( + child: stateWidget(), + ), + ], + ), ), ); } diff --git a/lib/presentation/pages/intro_page.dart b/lib/presentation/pages/intro_page.dart index 4a3364a..94437c0 100644 --- a/lib/presentation/pages/intro_page.dart +++ b/lib/presentation/pages/intro_page.dart @@ -16,9 +16,10 @@ class _IntroPageState extends State { GlobalKey(); String studyType = ''; + bool showNextButton = true; + IntroState state = IntroState.welcome; void nextPage() { - // TODO: Hide next button for sertan pages until element get selected _introKey.currentState?.next(); } @@ -47,7 +48,7 @@ class _IntroPageState extends State { }), ), PageViewModel( - title: 'Efficient $studyType Study', + title: 'Efficient $studyType Tips', bodyWidget: TipsOrganism(), ), PageViewModel( @@ -62,9 +63,50 @@ class _IntroPageState extends State { showBackButton: true, back: const Icon(Icons.arrow_back), next: const Icon(Icons.arrow_forward), + showNextButton: showNextButton, + scrollPhysics: const NeverScrollableScrollPhysics(), + onChange: (int n) { + state = IntroState.getStateByPageNumber(n); + bool showNextButtonTemp = true; + + if (state == IntroState.studyType && + (StudyTypeAbstract.instance?.studyType == null || + StudyTypeAbstract.instance!.studyType == + StudyType.undefined)) { + showNextButtonTemp = false; + } else if (state == IntroState.energy && + StudyTypeAbstract.instance!.energy == EnergyType.undefined) { + showNextButtonTemp = false; + } + setState(() { + showNextButton = showNextButtonTemp; + }); + }, showDoneButton: false, ), ), ); } } + +enum IntroState { + welcome(0), + studyType(1), + tips(2), + energy(3), + encouragementSentence(4), + ; + + const IntroState(this.pageNumber); + + final int pageNumber; + + static IntroState getStateByPageNumber(int number) { + for (final IntroState state in IntroState.values) { + if (state.pageNumber == number) { + return state; + } + } + return IntroState.welcome; + } +}