Skip to content

Commit

Permalink
Implementing activity back to home page
Browse files Browse the repository at this point in the history
  • Loading branch information
guyluz11 committed Nov 8, 2024
1 parent d31595c commit 5642179
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 28 deletions.
26 changes: 26 additions & 0 deletions lib/presentation/molecules/back_to_home_alert_dialog_molecule.dart
Original file line number Diff line number Diff line change
@@ -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(),
),
);
},
);
}
1 change: 1 addition & 0 deletions lib/presentation/molecules/molecules.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 3 additions & 0 deletions lib/presentation/molecules/page_enclosure_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -27,6 +28,7 @@ class PageEnclosureMolecule extends StatelessWidget {
final bool scaffold;
final TopBarType topBarType;
final VoidCallback? topBarRightOnTap;
final List<PopupMenuEntry<SampleItem>>? rightPopupMenu;
final bool expendChild;
final IconData? topBarRightIcon;

Expand All @@ -40,6 +42,7 @@ class PageEnclosureMolecule extends StatelessWidget {
margin: false,
translate: topBarTranslate,
rightOnTap: topBarRightOnTap,
rightPopupMenu: rightPopupMenu,
rightIcon: topBarRightIcon,
),
if (subTitle != null)
Expand Down
22 changes: 20 additions & 2 deletions lib/presentation/molecules/top_bar_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class TopBarMolecule extends StatelessWidget {
this.title,
this.leftOnTap,
this.rightOnTap,
this.rightPopupMenu,
this.translate = true,
this.margin = true,
this.rightIcon,
Expand All @@ -16,6 +17,9 @@ class TopBarMolecule extends StatelessWidget {
final String? title;
final VoidCallback? leftOnTap;
final VoidCallback? rightOnTap;

// TODO: Create atom for PopupMenuEntry
final List<PopupMenuEntry<SampleItem>>? rightPopupMenu;
final IconData? rightIcon;
final bool translate;
final bool margin;
Expand Down Expand Up @@ -52,14 +56,26 @@ class TopBarMolecule extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (rightPopupMenu != null)
PopupMenuButton<SampleItem>(
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,
Expand Down Expand Up @@ -125,3 +141,5 @@ class TopBarMolecule extends StatelessWidget {
}

enum TopBarType { none, back, close }

enum SampleItem { first, second }
13 changes: 12 additions & 1 deletion lib/presentation/organisms/timer_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,18 @@ class TimerOrganismState extends State<TimerOrganism> {
scaffold: false,
expendChild: false,
topMargin: false,
topBarRightOnTap: () => openAlertDialog(context, SettingsPage()),
rightPopupMenu: <PopupMenuEntry<SampleItem>>[
PopupMenuItem<SampleItem>(
value: SampleItem.first,
child: const Text('Navigate Home'),
onTap: () => backToHomePopup(context),
),
PopupMenuItem<SampleItem>(
value: SampleItem.second,
child: const Text('Settings'),
onTap: () => openAlertDialog(context, SettingsPage()),
),
],
child: Column(
children: [
ProgressTrackerAtom(
Expand Down
26 changes: 1 addition & 25 deletions lib/presentation/pages/activity_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -38,32 +37,9 @@ class _ActivityPageState extends State<ActivityPage>

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<bool> onWillPop(bool didPop, dynamic result) async {
if (_currentTabNum == 0) {
backToHomePopup();
backToHomePopup(context);
} else {
animateToPage(0);
}
Expand Down

0 comments on commit 5642179

Please sign in to comment.