Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
assert(arguments != null);
browserHistory.setRouteName(
arguments!.tryString('location'),
state: arguments.tryString('state'),
state: arguments['state'],
Copy link
Contributor

Choose a reason for hiding this comment

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

@yjbanov should we add a tryObject()?

Copy link
Contributor Author

@chunhtai chunhtai Aug 6, 2021

Choose a reason for hiding this comment

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

what is the point of tryObject though? it is already an object?

Copy link
Contributor

Choose a reason for hiding this comment

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

Without a type, it's dynamic not Object?. Not sure if that's an important distinction or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, feel free to submit the PR. If we need to change it to Object? we can do so later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add that if that makes sense, btw what is the motive to avoid as String? and use tryString

replace: arguments.tryBool('replace') ?? false,
);
return true;
Expand Down
42 changes: 42 additions & 0 deletions lib/web_ui/test/window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,48 @@ void testMain() {
expect(window.browserHistory.urlStrategy!.getPath(), '/foo');
});

test('should not throw when state is complex json object',
() async {
// Regression test https://github.com/flutter/flutter/issues/87823.
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',
// ignore: prefer_const_literals_to_create_immutables
<String, dynamic>{
'location': '/baz',
'state': <String, dynamic>{
'state1': true,
'state2': 1,
'state3': 'string',
'state4': <String, dynamic> {
'substate1': 1.0,
'substate2': 'string2',
}
},
},
)),
(_) { callback.complete(); },
);
await callback.future;
expect(window.browserHistory, isA<MultiEntriesBrowserHistory>());
expect(window.browserHistory.urlStrategy!.getPath(), '/baz');
final dynamic wrappedState = window.browserHistory.urlStrategy!.getState()!;
final dynamic actualState = wrappedState['state'];
expect(actualState['state1'], true);
expect(actualState['state2'], 1);
expect(actualState['state3'], 'string');
expect(actualState['state4']['substate1'], 1.0);
expect(actualState['state4']['substate2'], 'string2');
});

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