From 56421797f6324754cd7a77adf651540166ed5593 Mon Sep 17 00:00:00 2001 From: Guy Luz Date: Fri, 8 Nov 2024 16:01:26 +0700 Subject: [PATCH] Implementing activity back to home page --- .../back_to_home_alert_dialog_molecule.dart | 26 +++++++++++++++++++ lib/presentation/molecules/molecules.dart | 1 + .../molecules/page_enclosure_molecule.dart | 3 +++ .../molecules/top_bar_molecule.dart | 22 ++++++++++++++-- .../organisms/timer_organism.dart | 13 +++++++++- lib/presentation/pages/activity_page.dart | 26 +------------------ 6 files changed, 63 insertions(+), 28 deletions(-) create mode 100644 lib/presentation/molecules/back_to_home_alert_dialog_molecule.dart diff --git a/lib/presentation/molecules/back_to_home_alert_dialog_molecule.dart b/lib/presentation/molecules/back_to_home_alert_dialog_molecule.dart new file mode 100644 index 0000000..3d2a6c8 --- /dev/null +++ b/lib/presentation/molecules/back_to_home_alert_dialog_molecule.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:infinite_horizons/presentation/molecules/molecules.dart'; +import 'package:infinite_horizons/presentation/pages/pages.dart'; + +void backToHomePopup(BuildContext context) { + openAlertDialog( + context, + const SizedBox( + height: 150, + child: PageEnclosureMolecule( + title: 'Exit Session', + subTitle: 'Navigate back to Home Page?', + expendChild: false, + child: SizedBox(), + ), + ), + onConfirm: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => HomePage(), + ), + ); + }, + ); +} diff --git a/lib/presentation/molecules/molecules.dart b/lib/presentation/molecules/molecules.dart index 09cf571..3bfeca3 100644 --- a/lib/presentation/molecules/molecules.dart +++ b/lib/presentation/molecules/molecules.dart @@ -1,4 +1,5 @@ export 'package:infinite_horizons/presentation/molecules/alert_dialog_molecule.dart'; +export 'package:infinite_horizons/presentation/molecules/back_to_home_alert_dialog_molecule.dart'; export 'package:infinite_horizons/presentation/molecules/bottom_navigation_bar_home_molecule.dart'; export 'package:infinite_horizons/presentation/molecules/energy_selection_molecule.dart'; export 'package:infinite_horizons/presentation/molecules/page_enclosure_molecule.dart'; diff --git a/lib/presentation/molecules/page_enclosure_molecule.dart b/lib/presentation/molecules/page_enclosure_molecule.dart index d1af2d1..ec7bede 100644 --- a/lib/presentation/molecules/page_enclosure_molecule.dart +++ b/lib/presentation/molecules/page_enclosure_molecule.dart @@ -13,6 +13,7 @@ class PageEnclosureMolecule extends StatelessWidget { this.topBarType = TopBarType.none, this.scaffold = true, this.topBarRightOnTap, + this.rightPopupMenu, this.expendChild = true, this.topBarRightIcon, super.key, @@ -27,6 +28,7 @@ class PageEnclosureMolecule extends StatelessWidget { final bool scaffold; final TopBarType topBarType; final VoidCallback? topBarRightOnTap; + final List>? rightPopupMenu; final bool expendChild; final IconData? topBarRightIcon; @@ -40,6 +42,7 @@ class PageEnclosureMolecule extends StatelessWidget { margin: false, translate: topBarTranslate, rightOnTap: topBarRightOnTap, + rightPopupMenu: rightPopupMenu, rightIcon: topBarRightIcon, ), if (subTitle != null) diff --git a/lib/presentation/molecules/top_bar_molecule.dart b/lib/presentation/molecules/top_bar_molecule.dart index f5f7b27..24469e8 100644 --- a/lib/presentation/molecules/top_bar_molecule.dart +++ b/lib/presentation/molecules/top_bar_molecule.dart @@ -7,6 +7,7 @@ class TopBarMolecule extends StatelessWidget { this.title, this.leftOnTap, this.rightOnTap, + this.rightPopupMenu, this.translate = true, this.margin = true, this.rightIcon, @@ -16,6 +17,9 @@ class TopBarMolecule extends StatelessWidget { final String? title; final VoidCallback? leftOnTap; final VoidCallback? rightOnTap; + + // TODO: Create atom for PopupMenuEntry + final List>? rightPopupMenu; final IconData? rightIcon; final bool translate; final bool margin; @@ -52,14 +56,26 @@ class TopBarMolecule extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.end, children: [ + if (rightPopupMenu != null) + PopupMenuButton( + initialValue: SampleItem.values.first, + icon: const Icon(Icons.more_vert), + onSelected: (SampleItem item) { + // setState(() { + // selectedItem = item; + // }); + }, + itemBuilder: (BuildContext context) => + rightPopupMenu!, + ), if (rightOnTap != null) ButtonAtom( variant: ButtonVariant.lowEmphasisIcon, onPressed: rightOnTap!, translate: translate, icon: Icons.more_vert, - ) - else + ), + if (rightPopupMenu == null && rightOnTap == null) TextAtom( '', style: textTheme.headlineSmall, @@ -125,3 +141,5 @@ class TopBarMolecule extends StatelessWidget { } enum TopBarType { none, back, close } + +enum SampleItem { first, second } diff --git a/lib/presentation/organisms/timer_organism.dart b/lib/presentation/organisms/timer_organism.dart index 2d4d6f1..fe394f5 100644 --- a/lib/presentation/organisms/timer_organism.dart +++ b/lib/presentation/organisms/timer_organism.dart @@ -250,7 +250,18 @@ class TimerOrganismState extends State { scaffold: false, expendChild: false, topMargin: false, - topBarRightOnTap: () => openAlertDialog(context, SettingsPage()), + rightPopupMenu: >[ + PopupMenuItem( + value: SampleItem.first, + child: const Text('Navigate Home'), + onTap: () => backToHomePopup(context), + ), + PopupMenuItem( + value: SampleItem.second, + child: const Text('Settings'), + onTap: () => openAlertDialog(context, SettingsPage()), + ), + ], child: Column( children: [ ProgressTrackerAtom( diff --git a/lib/presentation/pages/activity_page.dart b/lib/presentation/pages/activity_page.dart index 7982aed..64599ed 100644 --- a/lib/presentation/pages/activity_page.dart +++ b/lib/presentation/pages/activity_page.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:infinite_horizons/domain/controllers/controllers.dart'; import 'package:infinite_horizons/presentation/molecules/molecules.dart'; import 'package:infinite_horizons/presentation/organisms/organisms.dart'; -import 'package:infinite_horizons/presentation/pages/home_page.dart'; class ActivityPage extends StatefulWidget { @override @@ -38,32 +37,9 @@ class _ActivityPageState extends State AppLifecycleState currentAppState = AppLifecycleState.resumed; - void backToHomePopup() { - openAlertDialog( - context, - const SizedBox( - height: 150, - child: PageEnclosureMolecule( - title: 'Exit Session', - subTitle: 'Navigate back to Home Page?', - expendChild: false, - child: SizedBox(), - ), - ), - onConfirm: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (context) => HomePage(), - ), - ); - }, - ); - } - Future onWillPop(bool didPop, dynamic result) async { if (_currentTabNum == 0) { - backToHomePopup(); + backToHomePopup(context); } else { animateToPage(0); }