flutter_issue_108697_workaround 0.1.0 copy "flutter_issue_108697_workaround: ^0.1.0" to clipboard
flutter_issue_108697_workaround: ^0.1.0 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.

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
0
pub points
49%
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

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_issue_108697_workaround