Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1556438
routes printing improved
hashirshoaeb May 10, 2024
dc9942a
Feature Debug Full Path
AbdullahAhmedSoomro May 12, 2024
fec3ee5
Merge pull request #2 from AbdullahAhmedSoomro/feature-debug-full-path
hashirshoaeb May 12, 2024
f58d4cd
formating updated
hashirshoaeb May 12, 2024
c913195
some fixes
hashirshoaeb May 12, 2024
a3e5b7e
version bump
hashirshoaeb May 12, 2024
8257693
docs updated
hashirshoaeb May 12, 2024
89caf08
formating updated
hashirshoaeb May 12, 2024
40894c4
some fixes
hashirshoaeb May 12, 2024
b9383a9
version bump
hashirshoaeb May 12, 2024
f5b7c81
docs updated
hashirshoaeb May 12, 2024
6b9582e
Merge branch 'feature-debug-full-path' of https://github.com/hashirsh…
hashirshoaeb May 12, 2024
415b13d
routes printing improved
hashirshoaeb May 10, 2024
129ecf8
Feature Debug Full Path
AbdullahAhmedSoomro May 12, 2024
f14dd8c
formating updated
hashirshoaeb May 12, 2024
80faceb
some fixes
hashirshoaeb May 12, 2024
26648b6
version bump
hashirshoaeb May 12, 2024
c4e9864
docs updated
hashirshoaeb May 12, 2024
34fa78f
Merge branch 'feature-debug-full-path' of https://github.com/hashirsh…
hashirshoaeb May 12, 2024
3d91f6d
minor printing fix
hashirshoaeb May 14, 2024
98a7cf3
sync with main Merge branch 'main' into feature-debug-full-path
hashirshoaeb May 14, 2024
8fe0e53
migic strings removed
hashirshoaeb May 17, 2024
c82d8b0
Merge remote-tracking branch 'origin/main' into feature-debug-full-path
hashirshoaeb May 17, 2024
c855781
added self in authors list
hashirshoaeb May 17, 2024
32cb9dd
Merge remote-tracking branch 'origin/main' into feature-debug-full-path
hashirshoaeb May 19, 2024
f154594
version bump
hashirshoaeb May 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
routes printing improved
  • Loading branch information
hashirshoaeb committed May 12, 2024
commit 415b13d8a16a6a3b420eb9d818549ee6469b3629
34 changes: 27 additions & 7 deletions packages/go_router/lib/src/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class RouteConfiguration {
String debugKnownRoutes() {
final StringBuffer sb = StringBuffer();
sb.writeln('Full paths for routes:');
_debugFullPathsFor(_routingConfig.value.routes, '', 0, sb);
_debugFullPathsFor(_routingConfig.value.routes, '', '', sb);

if (_nameToPath.isNotEmpty) {
sb.writeln('known full paths for route names:');
Expand All @@ -538,15 +538,35 @@ class RouteConfiguration {
}

void _debugFullPathsFor(List<RouteBase> routes, String parentFullpath,
int depth, StringBuffer sb) {
for (final RouteBase route in routes) {
String parentDecoration, StringBuffer sb) {
for (final (int index, RouteBase route) in routes.indexed) {
final String decoration =
_getDecoration(parentDecoration, index, routes.length);
String path = parentFullpath;
if (route is GoRoute) {
final String fullPath = concatenatePaths(parentFullpath, route.path);
sb.writeln(' => ${''.padLeft(depth * 2)}$fullPath');
_debugFullPathsFor(route.routes, fullPath, depth + 1, sb);
path = concatenatePaths(parentFullpath, route.path);
final String screenName =
route.builder?.runtimeType.toString().split('=> ').last ?? '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this always be Widget?

maybe just use GoRoute and GoRoute(redirectOnly)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

screenName is the name of the widget. it will not always print Widget. Otherwise it was for no use.
Just like in the logging_test.dart test it logs / (Text)

Example from my app:

[GoRouter] Full paths for routes:
           ├─/ (SplashScreen)
           ├─/intro (IntroScreen)
           ├─ (ShellRoute)
           │ ├─/main/year ()
           │ │ └─/main/year/month (HomeScreen)
           │ └─/main/profile (ProfileScreen)
           │   ├─/main/profile/analytics (AnalyticsScreen)
           │   └─/main/profile/settings (SettingsScreen)
           │     └─/main/profile/settings/license (LicenseAgreementScreen)
           └─/journal (JournalsListScreen)
             ├─/journal/new (JournalCreateScreen)
             └─/journal/:id (JournalDetailScreen)
               └─/journal/:id/edit (JournalEditScreen)

There are edge cases:

  • screenName is only get printed, when user uses GoRouter.builder
  • It does not print for GoRouter.pageBuilder
  • It prints (Never) when GoRouter.builder throws Unimplemented Error

sb.writeln('$decoration$path ($screenName)'
'${route.name == null ? '' : ' (${route.name})'}');
} else if (route is ShellRouteBase) {
_debugFullPathsFor(route.routes, parentFullpath, depth, sb);
sb.writeln('$decoration$parentFullpath (ShellRoute)');
}
_debugFullPathsFor(route.routes, path, decoration, sb);
}
}

String _getDecoration(
String parentDecoration,
int index,
int length,
) {
final String newDecoration =
parentDecoration.replaceAll('├─', '│ ').replaceAll('└─', ' ');
if (index == length - 1) {
return '$newDecoration└─';
} else {
return '$newDecoration├─';
}
}

Expand Down