'How to not dispose of previous widget when navigating to a new widget in Flutter?

What I am currently doing

Navigator.push(context,
            RouteAnimationFadeIn(NewWidget(someValue), true));

RouteAnimationFadeIn:

class RouteAnimationFadeIn extends PageRouteBuilder {
final Widget widget;
final bool shouldMaintainState;

RouteAnimationFadeIn(this.widget, this.shouldMaintainState)
  : super(pageBuilder: (BuildContext context, Animation<double> animation,
        Animation<double> secondaryAnimation) {
      return widget;
    }, transitionsBuilder: (BuildContext context,
        Animation<double> animation,
        Animation<double> secondaryAnimation,
        Widget child) {
      return FadeTransition(
        opacity: animation,
        child: child,
      );
    });

@override
bool get maintainState {
  return shouldMaintainState;
}
}

This disposes of the previous widget, which consequently disposes of data of all the form fields in it. What I want is a fragment add like the functionality of Android, so that the new widget opens on tap of the old widget so that, when I use Navigator.pop(context); I see the old data in it.

I tried this, but it doesn't work.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source