I'm building an app in Flutter and I'm trying to allow my pages to be restorable, even though some arguments are passed to those pages.
My code:
Main:
child: MaterialApp(
restorationScopeId: 'root_app',
onGenerateRoute: Routes.buildRoutes(),
title: 'My App',
theme: ThemeData(primarySwatch: Colors.teal),
)
Routing:
static RouteFactory buildRoutes() {
return (settings) {
final arguments = settings.arguments != null ? settings.arguments as Map<String, dynamic> : <String, dynamic>{};
Widget _view;
var route = findRoute(settings.name);
switch (route) {
case Routes.menu:
_view = const Menu();
break;
case Routes.selection:
_view = const Page2(arguments);
break;
default:
return null;
}
return MaterialPageRoute(
settings: settings,
builder: (context) => RestorationScope(restorationId: route.restorationId, child: _view),
);
};
}
Navigation:
onSuccess: (List<Map<String, dynamic>> evalData) =>
Navigator.restorablePushReplacementNamed(context, widget._route.value, arguments: <String, dynamic>{'data': evalData}),
When I run the following code for the first time (not from a restoration, but by navigation) I get NO errors and my page loads normally.
When I put the app in the background (with don't keep alive) and bring it back, forcing a restoration, I get a "_InternalLinkedHashMap cast" error and the debugger data is as follows:
It's interesting to note that the data itself is pushed and works the first time, being passed by navigation. But when this data is restored (correctly according to the debugger) I get an error while trying to cast it.
I did found something similar at Github and also this is a version working thanks to this answer by @pskink
I also decided to raise an issue at Flutter's github.

