Skip to content

Commit

Permalink
Merge pull request #191 from guyluz11/Start-a-new-activity-button-#190
Browse files Browse the repository at this point in the history
Implementing activity back to home page
  • Loading branch information
guyluz11 authored Nov 9, 2024
2 parents d31595c + 129fc2a commit 67e69d3
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 28 deletions.
1 change: 1 addition & 0 deletions lib/presentation/atoms/atoms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export 'package:infinite_horizons/presentation/atoms/confetti_atom.dart';
export 'package:infinite_horizons/presentation/atoms/image_atom.dart';
export 'package:infinite_horizons/presentation/atoms/list_tile_atom.dart';
export 'package:infinite_horizons/presentation/atoms/margined_expanded_atom.dart';
export 'package:infinite_horizons/presentation/atoms/popup_menu_entry_atom.dart';
export 'package:infinite_horizons/presentation/atoms/progress_indicator_atom.dart';
export 'package:infinite_horizons/presentation/atoms/separator_atom.dart';
export 'package:infinite_horizons/presentation/atoms/text_atom.dart';
Expand Down
35 changes: 35 additions & 0 deletions lib/presentation/atoms/popup_menu_entry_atom.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:flutter/material.dart';

class PopupMenuEntryAtom<T extends Enum> extends PopupMenuEntry<T> {
const PopupMenuEntryAtom({
required this.value,
required this.child,
required this.onTap,
});

final T value;
final Widget child;
final VoidCallback onTap;

@override
double get height => 50.0;

@override
bool represents(T? value) {
return value != null && value == this.value;
}

@override
State createState() => _CustomPopupMenuEntryState<T>();
}

class _CustomPopupMenuEntryState<T extends Enum>
extends State<PopupMenuEntryAtom<T>> {
@override
Widget build(BuildContext context) {
return ListTile(
title: widget.child,
onTap: widget.onTap,
);
}
}
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<PopupMenuEntryAtom<Enum>>? 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
13 changes: 11 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,8 @@ class TopBarMolecule extends StatelessWidget {
final String? title;
final VoidCallback? leftOnTap;
final VoidCallback? rightOnTap;

final List<PopupMenuEntryAtom>? rightPopupMenu;
final IconData? rightIcon;
final bool translate;
final bool margin;
Expand Down Expand Up @@ -52,14 +55,20 @@ class TopBarMolecule extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
if (rightPopupMenu != null)
PopupMenuButton(
icon: const Icon(Icons.more_vert),
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
16 changes: 15 additions & 1 deletion lib/presentation/organisms/timer_organism.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:infinite_horizons/domain/controllers/controllers.dart';
import 'package:infinite_horizons/domain/objects/energy_level.dart';
import 'package:infinite_horizons/domain/objects/work_type_abstract.dart';
import 'package:infinite_horizons/presentation/atoms/atoms.dart';
import 'package:infinite_horizons/presentation/atoms/progress_tracker_atom.dart';
import 'package:infinite_horizons/presentation/molecules/molecules.dart';
import 'package:infinite_horizons/presentation/organisms/organisms.dart';
Expand Down Expand Up @@ -250,7 +251,18 @@ class TimerOrganismState extends State<TimerOrganism> {
scaffold: false,
expendChild: false,
topMargin: false,
topBarRightOnTap: () => openAlertDialog(context, SettingsPage()),
rightPopupMenu: <PopupMenuEntryAtom<PopMenuEnum>>[
PopupMenuEntryAtom<PopMenuEnum>(
value: PopMenuEnum.navigationHome,
child: const TextAtom('Navigate Home'),
onTap: () => backToHomePopup(context),
),
PopupMenuEntryAtom<PopMenuEnum>(
value: PopMenuEnum.setting,
child: const TextAtom('Settings'),
onTap: () => openAlertDialog(context, SettingsPage()),
),
],
child: Column(
children: [
ProgressTrackerAtom(
Expand Down Expand Up @@ -288,3 +300,5 @@ extension TimerStateExtension on TimerState {
);
}
}

enum PopMenuEnum { navigationHome, setting }
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 67e69d3

Please sign in to comment.