Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #173 from 2rabs/rt/refactor-schedules-router
Browse files Browse the repository at this point in the history
👍 トップページからスケジュール一覧ページへの遷移をアプリケーション層で行うように変更
  • Loading branch information
tatsutakein authored Apr 20, 2023
2 parents f0b18a2 + 661a115 commit ea5a927
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
13 changes: 8 additions & 5 deletions apps/frontend/lib/src/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class RootRoute extends GoRouteData {
onSettingsActionPressed: (BuildContext context) {
context.push('/settings');
},
onScheduleListButtonPressed: () {
const ScheduleListRoute().push(context);
},
);
}

Expand All @@ -44,12 +47,12 @@ class SettingsRoute extends GoRouteData {
build(BuildContext context, GoRouterState state) => const SettingsScreen();
}

/// スケジュールページルート
@TypedGoRoute<ScheduleRoute>(
path: '/schedule',
/// スケジュール一覧ページルート
@TypedGoRoute<ScheduleListRoute>(
path: '/schedules',
)
class ScheduleRoute extends GoRouteData {
const ScheduleRoute();
class ScheduleListRoute extends GoRouteData {
const ScheduleListRoute();

@override
build(BuildContext context, GoRouterState state) => const SchedulePage();
Expand Down
15 changes: 8 additions & 7 deletions apps/frontend/lib/src/router/router.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/feature/top/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TopPageTest extends HookConsumerWidget {
return MaterialApp(
home: TopPage(
onSettingsActionPressed: (BuildContext context) {},
onScheduleListButtonPressed: () {},
),
);
}
Expand Down
13 changes: 9 additions & 4 deletions packages/feature/top/lib/src/ui/top_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ import 'package:flutter/material.dart';
import 'package:feature_top/src/ui/top_page_for_mobile.dart';

class TopPage extends StatelessWidget {
const TopPage(
{super.key,
required void Function(BuildContext context) onSettingsActionPressed})
: _onSettingsActionPressed = onSettingsActionPressed;
const TopPage({
super.key,
required void Function(BuildContext context) onSettingsActionPressed,
required VoidCallback onScheduleListButtonPressed,
}) : _onSettingsActionPressed = onSettingsActionPressed,
_onScheduleListButtonPressed = onScheduleListButtonPressed;

final void Function(BuildContext context) _onSettingsActionPressed;
final VoidCallback _onScheduleListButtonPressed;

@override
Widget build(BuildContext context) {
// FIXME(Daichi): 今後WEBとMOBILEで分岐する際に修正
return kIsWeb
? TopPageForMobile(
onSettingsActionPressed: () => _onSettingsActionPressed(context),
onScheduleListButtonPressed: _onScheduleListButtonPressed,
)
: TopPageForMobile(
onSettingsActionPressed: () => _onSettingsActionPressed(context),
onScheduleListButtonPressed: _onScheduleListButtonPressed,
);
}
}
8 changes: 5 additions & 3 deletions packages/feature/top/lib/src/ui/top_page_body.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import 'package:feature_top/src/ui/top_page_schedule_tile.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';

class TopPageBody extends StatelessWidget {
const TopPageBody({
super.key,
});
required VoidCallback onScheduleListButtonPressed,
}) : _onScheduleListButtonPressed = onScheduleListButtonPressed;

final VoidCallback _onScheduleListButtonPressed;

@override
Widget build(BuildContext context) {
Expand All @@ -15,8 +17,8 @@ class TopPageBody extends StatelessWidget {
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: _onScheduleListButtonPressed,
child: const Text('スケジュール一覧を見る'),
onPressed: () => context.go('/schedule'),
),
),
const Spacer(),
Expand Down
14 changes: 10 additions & 4 deletions packages/feature/top/lib/src/ui/top_page_for_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import 'package:feature_top/src/ui/top_page_body.dart';
import 'package:flutter/material.dart';

class TopPageForMobile extends StatelessWidget {
const TopPageForMobile(
{super.key, required VoidCallback onSettingsActionPressed})
: _onSettingsActionPressed = onSettingsActionPressed;
const TopPageForMobile({
super.key,
required VoidCallback onSettingsActionPressed,
required VoidCallback onScheduleListButtonPressed,
}) : _onSettingsActionPressed = onSettingsActionPressed,
_onScheduleListButtonPressed = onScheduleListButtonPressed;

final VoidCallback _onSettingsActionPressed;
final VoidCallback _onScheduleListButtonPressed;

@override
Widget build(BuildContext context) {
Expand All @@ -22,7 +26,9 @@ class TopPageForMobile extends StatelessWidget {
icon: const Icon(Icons.settings))
],
),
body: const TopPageBody(),
body: TopPageBody(
onScheduleListButtonPressed: _onScheduleListButtonPressed,
),
);
}
}

0 comments on commit ea5a927

Please sign in to comment.