Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit ea4b353

Browse files
authored
Fix routerinformationupdate can take complex json (#27932)
* Fix routerinformationupdate can take complex json * comment
1 parent e4a8d23 commit ea4b353

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

lib/web_ui/lib/src/engine/window.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class EngineFlutterWindow extends ui.SingletonFlutterWindow {
171171
assert(arguments != null);
172172
browserHistory.setRouteName(
173173
arguments!.tryString('location'),
174-
state: arguments.tryString('state'),
174+
state: arguments['state'],
175175
replace: arguments.tryBool('replace') ?? false,
176176
);
177177
return true;

lib/web_ui/test/window_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,48 @@ void testMain() {
237237
expect(window.browserHistory.urlStrategy!.getPath(), '/foo');
238238
});
239239

240+
test('should not throw when state is complex json object',
241+
() async {
242+
// Regression test https://github.com/flutter/flutter/issues/87823.
243+
await window.debugInitializeHistory(TestUrlStrategy.fromEntry(
244+
const TestHistoryEntry('initial state', null, '/initial'),
245+
), useSingle: false);
246+
expect(window.browserHistory, isA<MultiEntriesBrowserHistory>());
247+
248+
// routeInformationUpdated does not
249+
final Completer<void> callback = Completer<void>();
250+
window.sendPlatformMessage(
251+
'flutter/navigation',
252+
const JSONMethodCodec().encodeMethodCall(const MethodCall(
253+
'routeInformationUpdated',
254+
// ignore: prefer_const_literals_to_create_immutables
255+
<String, dynamic>{
256+
'location': '/baz',
257+
'state': <String, dynamic>{
258+
'state1': true,
259+
'state2': 1,
260+
'state3': 'string',
261+
'state4': <String, dynamic> {
262+
'substate1': 1.0,
263+
'substate2': 'string2',
264+
}
265+
},
266+
},
267+
)),
268+
(_) { callback.complete(); },
269+
);
270+
await callback.future;
271+
expect(window.browserHistory, isA<MultiEntriesBrowserHistory>());
272+
expect(window.browserHistory.urlStrategy!.getPath(), '/baz');
273+
final dynamic wrappedState = window.browserHistory.urlStrategy!.getState()!;
274+
final dynamic actualState = wrappedState['state'];
275+
expect(actualState['state1'], true);
276+
expect(actualState['state2'], 1);
277+
expect(actualState['state3'], 'string');
278+
expect(actualState['state4']['substate1'], 1.0);
279+
expect(actualState['state4']['substate2'], 'string2');
280+
});
281+
240282
test('can replace in MultiEntriesBrowserHistory',
241283
() async {
242284
await window.debugInitializeHistory(TestUrlStrategy.fromEntry(

0 commit comments

Comments
 (0)