flutter_issue_108697_workaround 0.1.3 copy "flutter_issue_108697_workaround: ^0.1.3" to clipboard
flutter_issue_108697_workaround: ^0.1.3 copied to clipboard

A workaround for Flutter Issue 108697 that prevents state recovery on page refresh. Gets the state directly from the browser History API.

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

Screen

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.
  }
  // ...
}

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),
);
6
likes
150
pub points
32%
popularity

Publisher

verified publisherainkin.com

A workaround for Flutter Issue 108697 that prevents state recovery on page refresh. Gets the state directly from the browser History API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT-0 (license)

Dependencies

flutter

More

Packages that depend on flutter_issue_108697_workaround