Skip to content

Commit a36ed7d

Browse files
committed
fix music navigation back
1 parent a1f538e commit a36ed7d

File tree

4 files changed

+59
-35
lines changed

4 files changed

+59
-35
lines changed

lib/config/routes.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class Routes {
1010
static const String playOption = '/play_option';
1111
static const String sleepMusic = '/sleep_music';
1212
static const String welcome = '/welcome';
13+
static const String music = '/music';
1314

1415
static Route<dynamic> generateRoute(RouteSettings settings) {
1516
switch (settings.name) {
@@ -29,6 +30,8 @@ class Routes {
2930
return MaterialPageRoute(builder: (_) => const SleepMusic());
3031
case welcome:
3132
return MaterialPageRoute(builder: (_) => const WelcomePage());
33+
case music:
34+
return MaterialPageRoute(builder: (_) => const MusicPage());
3235
case '/':
3336
default:
3437
return MaterialPageRoute(

lib/screen/menu/music.dart

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter/widgets.dart';
23
import 'package:flutter_svg/flutter_svg.dart';
34
import 'package:flutter_ui_meditation_app/components/app_circle_button.dart';
45

@@ -21,7 +22,10 @@ class _MusicPageState extends State<MusicPage> {
2122

2223
@override
2324
Widget build(BuildContext context) {
25+
final isFirstRoute = Navigator.of(context).canPop() ==
26+
false; // True jika halaman ini adalah yang pertama
2427
bool isDarkMode = Theme.of(context).brightness == Brightness.dark;
28+
2529
return Scaffold(
2630
backgroundColor: isDarkMode
2731
? const Color(0xFF02174C)
@@ -92,15 +96,20 @@ class _MusicPageState extends State<MusicPage> {
9296
),
9397
),
9498
),
95-
const Padding(
96-
padding: EdgeInsets.symmetric(vertical: 50, horizontal: 20),
99+
Padding(
100+
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
97101
child: Column(
98102
children: [
99103
Row(
100104
mainAxisAlignment: MainAxisAlignment.spaceBetween,
101105
children: [
102-
AppCircleButton(),
103-
Row(
106+
Visibility(
107+
visible: !isFirstRoute,
108+
child: AppCircleButton(
109+
onTap: () => Navigator.pop(context),
110+
),
111+
),
112+
const Row(
104113
children: [
105114
AppCircleButton(
106115
isTransparent: true,

lib/screen/play_on.dart

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import 'package:flutter/material.dart';
44
import 'package:flutter_ui_meditation_app/components/components.dart';
55

6+
import '../config/routes.dart';
67
import 'menu/home/components/app_card_tile.dart';
78

89
class PlayOnPage extends StatefulWidget {
@@ -457,37 +458,40 @@ class MusicTile extends StatelessWidget {
457458

458459
@override
459460
Widget build(BuildContext context) {
460-
return Padding(
461-
padding: const EdgeInsets.all(8.0),
462-
child: Row(
463-
children: [
464-
Container(
465-
height: 40,
466-
width: 40,
467-
decoration: BoxDecoration(
468-
color: Theme.of(context).primaryColor,
469-
borderRadius: BorderRadius.circular(40),
470-
),
471-
child: Icon(
472-
Icons.play_arrow_rounded,
473-
color: Colors.white,
474-
),
475-
),
476-
SizedBox(width: 20),
477-
Column(
478-
crossAxisAlignment: CrossAxisAlignment.start,
479-
children: [
480-
Text(
481-
title,
482-
style: Theme.of(context).textTheme.bodyMedium,
461+
return GestureDetector(
462+
onTap: () => Navigator.of(context).pushNamed(Routes.music),
463+
child: Padding(
464+
padding: const EdgeInsets.all(8.0),
465+
child: Row(
466+
children: [
467+
Container(
468+
height: 40,
469+
width: 40,
470+
decoration: BoxDecoration(
471+
color: Theme.of(context).primaryColor,
472+
borderRadius: BorderRadius.circular(40),
483473
),
484-
Text(
485-
duration,
486-
style: Theme.of(context).textTheme.bodySmall,
474+
child: Icon(
475+
Icons.play_arrow_rounded,
476+
color: Colors.white,
487477
),
488-
],
489-
),
490-
],
478+
),
479+
SizedBox(width: 20),
480+
Column(
481+
crossAxisAlignment: CrossAxisAlignment.start,
482+
children: [
483+
Text(
484+
title,
485+
style: Theme.of(context).textTheme.bodyMedium,
486+
),
487+
Text(
488+
duration,
489+
style: Theme.of(context).textTheme.bodySmall,
490+
),
491+
],
492+
),
493+
],
494+
),
491495
),
492496
);
493497
}

lib/screen/reminders.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,20 @@ class _RemindersPageState extends State<RemindersPage> {
106106
children: [
107107
AppButton(
108108
'SAVE',
109-
onTap: () => Navigator.pushNamed(context, Routes.menu),
109+
onTap: () => Navigator.pushNamedAndRemoveUntil(
110+
context,
111+
Routes.menu,
112+
(Route<dynamic> route) => false,
113+
),
110114
),
111115
const SizedBox(height: 10),
112116
Center(
113117
child: GestureDetector(
114-
onTap: () => Navigator.pushNamed(context, Routes.menu),
118+
onTap: () => Navigator.pushNamedAndRemoveUntil(
119+
context,
120+
Routes.menu,
121+
(Route<dynamic> route) => false,
122+
),
115123
child: Text(
116124
'NO THANKS',
117125
style: Theme.of(context).textTheme.titleSmall,

0 commit comments

Comments
 (0)