-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #266 from yumemi-inc/feature/navigation_debug
デバッグ時に、任意の画面にすぐ遷移できるようにする
- Loading branch information
Showing
11 changed files
with
253 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
packages/features/debug_mode/lib/src/ui/navigation_debug_page.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_hooks/flutter_hooks.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:go_router/go_router.dart'; | ||
|
||
class NavigationDebugPage extends ConsumerWidget { | ||
const NavigationDebugPage({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context, WidgetRef ref) { | ||
return const Scaffold( | ||
body: CustomScrollView( | ||
slivers: [ | ||
SliverAppBar.large( | ||
title: Text('Debug Page'), | ||
), | ||
SliverToBoxAdapter( | ||
child: Padding( | ||
padding: EdgeInsets.symmetric(horizontal: 16), | ||
child: RouteDropdownMenu(), | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
final class RouteDropdownMenu extends HookWidget { | ||
const RouteDropdownMenu({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final router = GoRouter.of(context); | ||
final routeBases = router.configuration.routes; | ||
final dropdownMenuEntries = useMemoized( | ||
() { | ||
final routes = routeBases.toRoutes(); | ||
return routes | ||
.map( | ||
(route) { | ||
final routePath = route.path; | ||
|
||
// デバッグ関連のルートは除外する | ||
if (routePath.contains('debug')) { | ||
return null; | ||
} | ||
return DropdownMenuEntry<_Route>( | ||
value: route, | ||
label: routePath, | ||
); | ||
}, | ||
) | ||
.nonNulls | ||
.toList(); | ||
}, | ||
routeBases, | ||
); | ||
// DropdownMenu を親の横幅に合わせる | ||
return LayoutBuilder( | ||
builder: (context, constraints) { | ||
return DropdownMenu<_Route>( | ||
width: constraints.maxWidth, | ||
dropdownMenuEntries: dropdownMenuEntries, | ||
// hintText: l.routeDropDownHintText, | ||
onSelected: (route) { | ||
if (route == null) { | ||
return; | ||
} | ||
router.go(route.path); | ||
}, | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
extension _ToRoutes on List<RouteBase> { | ||
List<_Route> toRoutes([_Route? parentRoute]) { | ||
final routes = <_Route>[]; | ||
for (final routeBase in this) { | ||
switch (routeBase) { | ||
case GoRoute(): | ||
final route = _Route( | ||
goRoute: routeBase, | ||
parentRoute: parentRoute, | ||
); | ||
routes.add(route); | ||
|
||
final childRouteBases = routeBase.routes; | ||
if (childRouteBases.isNotEmpty) { | ||
routes.addAll(childRouteBases.toRoutes(route)); | ||
} | ||
case ShellRoute() || StatefulShellRoute(): | ||
routes.addAll(routeBase.routes.toRoutes()); | ||
} | ||
} | ||
return routes; | ||
} | ||
} | ||
|
||
final class _Route { | ||
_Route({ | ||
required GoRoute goRoute, | ||
_Route? parentRoute, | ||
}) : _goRoute = goRoute, | ||
_parentRoute = parentRoute; | ||
|
||
final GoRoute _goRoute; | ||
final _Route? _parentRoute; | ||
|
||
late final String path = _path; | ||
|
||
String get _path { | ||
final parentPath = _parentRoute?._path; | ||
final childPath = _goRoute.path; | ||
if (parentPath == null) { | ||
return childPath; | ||
} | ||
|
||
return '${parentPath == '/' ? '' : parentPath}/$childPath'; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
packages/features/debug_mode/lib/src/ui/provider/navigator_provider.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'package:features_debug_mode/ui.dart'; | ||
import 'package:riverpod_annotation/riverpod_annotation.dart'; | ||
|
||
part 'navigator_provider.g.dart'; | ||
|
||
@Riverpod(dependencies: []) | ||
DebugPageNavigator debugPageNavigator(DebugPageNavigatorRef ref) => | ||
throw UnimplementedError(); |
29 changes: 29 additions & 0 deletions
29
packages/features/debug_mode/lib/src/ui/provider/navigator_provider.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export 'src/ui/debug_page.dart'; | ||
export 'src/ui/maintenance_page.dart'; | ||
export 'src/ui/navigation_debug_page.dart'; | ||
export 'src/ui/provider/navigator_provider.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters