Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,4 @@ Daniele Cambi <[email protected]>
Michele Benedetti <[email protected]>
Taskulu LDA <[email protected]>
LinXunFeng <[email protected]>
Hashir Shoaib <[email protected]>
1 change: 1 addition & 0 deletions packages/go_router/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@

Google Inc.
[email protected]
Hashir Shoaib <[email protected]>
4 changes: 4 additions & 0 deletions packages/go_router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 14.1.3

- Improves the logging of routes when `debugLogDiagnostics` is enabled or `debugKnownRoutes() is called. Explains the position of shell routes in the route tree. Prints the widget name of the routes it is building.

## 14.1.2

- Fixes issue that path parameters are not set when using the `goBranch`.
Expand Down
65 changes: 58 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,8 @@ class RouteConfiguration {
String debugKnownRoutes() {
final StringBuffer sb = StringBuffer();
sb.writeln('Full paths for routes:');
_debugFullPathsFor(_routingConfig.value.routes, '', 0, sb);
_debugFullPathsFor(
_routingConfig.value.routes, '', const <_DecorationType>[], sb);

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

void _debugFullPathsFor(List<RouteBase> routes, String parentFullpath,
int depth, StringBuffer sb) {
for (final RouteBase route in routes) {
List<_DecorationType> parentDecoration, StringBuffer sb) {
for (final (int index, RouteBase route) in routes.indexed) {
final List<_DecorationType> decoration =
_getDecoration(parentDecoration, index, routes.length);
final String decorationString =
decoration.map((_DecorationType e) => e.toString()).join();
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;
sb.writeln('$decorationString$path '
'${screenName == null ? '' : '($screenName)'}');
} else if (route is ShellRouteBase) {
_debugFullPathsFor(route.routes, parentFullpath, depth, sb);
sb.writeln('$decorationString (ShellRoute)');
}
_debugFullPathsFor(route.routes, path, decoration, sb);
}
}

List<_DecorationType> _getDecoration(
List<_DecorationType> parentDecoration,
int index,
int length,
) {
final Iterable<_DecorationType> newDecoration =
parentDecoration.map((_DecorationType e) {
switch (e) {
// swap
case _DecorationType.branch:
return _DecorationType.parentBranch;
case _DecorationType.leaf:
return _DecorationType.none;
// no swap
case _DecorationType.parentBranch:
return _DecorationType.parentBranch;
case _DecorationType.none:
return _DecorationType.none;
}
});
if (index == length - 1) {
return <_DecorationType>[...newDecoration, _DecorationType.leaf];
} else {
return <_DecorationType>[...newDecoration, _DecorationType.branch];
}
}

Expand Down Expand Up @@ -575,3 +611,18 @@ class RouteConfiguration {
}
}
}

enum _DecorationType {
parentBranch('│ '),
branch('├─'),
leaf('└─'),
none(' '),
;

const _DecorationType(this.value);

final String value;

@override
String toString() => value;
}
2 changes: 1 addition & 1 deletion packages/go_router/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: go_router
description: A declarative router for Flutter based on Navigation 2 supporting
deep linking, data-driven routes and more
version: 14.1.2
version: 14.1.3
repository: https://github.com/flutter/packages/tree/main/packages/go_router
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+go_router%22

Expand Down
20 changes: 11 additions & 9 deletions packages/go_router/test/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1070,15 +1070,17 @@ void main() {
},
).debugKnownRoutes(),
'Full paths for routes:\n'
' => /a\n'
' => /a/b\n'
' => /a/c\n'
' => /d\n'
' => /d/e\n'
' => /d/e/f\n'
' => /g\n'
' => /g/h\n'
' => /g/i\n',
'├─/a (Widget)\n'
'│ └─ (ShellRoute)\n'
'│ ├─/a/b (Widget)\n'
'│ └─/a/c (Widget)\n'
'├─/d (Widget)\n'
'│ └─/d/e (Widget)\n'
'│ └─/d/e/f (Widget)\n'
'└─/g (Widget)\n'
' └─ (ShellRoute)\n'
' ├─/g/h (Widget)\n'
' └─/g/i (Widget)\n',
);
},
);
Expand Down
4 changes: 2 additions & 2 deletions packages/go_router/test/logging_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void main() {
expect(
logs,
const <String>[
'Full paths for routes:\n => /\n',
'Full paths for routes:\n└─/ (Text)\n',
'setting initial location null'
],
reason: 'Go router should have sent the 2 events to the logger',
Expand Down Expand Up @@ -110,7 +110,7 @@ void main() {
expect(
logs,
const <String>[
'Full paths for routes:\n => /\n',
'Full paths for routes:\n└─/ (Text)\n',
'setting initial location null'
],
reason: 'Go router should have sent the 2 events to the logger',
Expand Down