flutter_issue_108697_workaround

Last updated:

0 purchases

flutter_issue_108697_workaround Image
flutter_issue_108697_workaround Images
Add to Cart

Description:

flutter issue 108697 workaround

A workaround for Flutter Issue 108697
that prevents state recovery on page refresh. Gets the state directly from the browser History API.
Example #
This app preserves the text on page refresh.
Runnable project: https://github.com/alexeyinkin/flutter-issue-108697-workaround/blob/main/example/main.dart

Usage #
Add this code to your RouteInformationParser:
import 'package:flutter/widgets.dart';
import 'package:flutter_issue_108697_workaround/flutter_issue_108697_workaround.dart'; // ADDED

class MyRouteInformationParser extends RouteInformationParser {
@override
Future<Object> parseRouteInformation(RouteInformation routeInformation) async {
routeInformation = apply108697Workaround(routeInformation); // ADDED
// ... continue your parsing.
}
// ...
}
copied to clipboard
The method is deliberately named awkward so you periodically stumble onto it while reading your
code and check if the issue is fixed in Flutter yet so you can remove this workaround later.
The Workaround #
If not in web, does nothing.
In web, if RouteInformation.state is not null, does nothing.
Otherwise, checks the state directly with the browser's History API like this:
final stateJson = js.context.callMethod(
'eval',
['JSON.stringify(history.state.state)'],
);

return RouteInformation(
location: routeInformation.location,
state: jsonDecode(stateJson),
);
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.