Skip to content

Commit

Permalink
Added additional uri field to routeInformationUpdated to accept entir… (
Browse files Browse the repository at this point in the history
flutter#40250)

Added additional uri field to routeInformationUpdated to accept entir�
  • Loading branch information
chunhtai authored and eyebrowsoffire committed Mar 27, 2023
1 parent 429ee91 commit 16b4dad
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,23 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
return true;
case 'routeInformationUpdated':
assert(arguments != null);
final String? uriString = arguments!.tryString('uri');
final String path;
if (uriString != null) {
final Uri uri = Uri.parse(uriString);
// Need to remove scheme and authority.
path = Uri.decodeComponent(
Uri(
path: uri.path.isEmpty ? '/' : uri.path,
queryParameters: uri.queryParametersAll.isEmpty ? null : uri.queryParametersAll,
fragment: uri.fragment.isEmpty ? null : uri.fragment,
).toString(),
);
} else {
path = arguments.tryString('location')!;
}
browserHistory.setRouteName(
arguments!.tryString('location'),
path,
state: arguments['state'],
replace: arguments.tryBool('replace') ?? false,
);
Expand Down
24 changes: 24 additions & 0 deletions lib/web_ui/test/engine/routing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,30 @@ void testMain() {
expect(actualState['state4']['substate2'], 'string2');
});

test('routeInformationUpdated can handle uri',
() async {
await window.debugInitializeHistory(TestUrlStrategy.fromEntry(
const TestHistoryEntry('initial state', null, '/initial'),
), useSingle: false);
expect(window.browserHistory, isA<MultiEntriesBrowserHistory>());

// routeInformationUpdated does not
final Completer<void> callback = Completer<void>();
window.sendPlatformMessage(
'flutter/navigation',
const JSONMethodCodec().encodeMethodCall(const MethodCall(
'routeInformationUpdated',
<String, dynamic>{
'uri': 'http://myhostname.com/baz?abc=def#fragment',
},
)),
(_) { callback.complete(); },
);
await callback.future;
expect(window.browserHistory, isA<MultiEntriesBrowserHistory>());
expect(window.browserHistory.urlStrategy!.getPath(), '/baz?abc=def#fragment');
});

test('can replace in MultiEntriesBrowserHistory',
() async {
await window.debugInitializeHistory(TestUrlStrategy.fromEntry(
Expand Down

0 comments on commit 16b4dad

Please sign in to comment.