Search code examples
flutterdartflutter-animation

Custom route transaction error in flutter


I was trying to implement custom animations for a screen but I'm encountering an error.

The error is:

The getter 'isInitialRoute' isn't defined for the type 'RouteSettings'.

This is my code...

class MyCustomRoute<T> extends MaterialPageRoute<T> {
      MyCustomRoute({ WidgetBuilder builder, RouteSettings settings })
          : super(builder: builder, settings: settings);

      @override
      Widget buildTransitions(BuildContext context,
          Animation<double> animation,
          Animation<double> secondaryAnimation,
          Widget child) {
        if (settings.isInitialRoute)
          return child;
        // Fades between routes. (If you don't want any animation, 
        // just return child.)
        return new FadeTransition(opacity: animation, child: child);
      }
    }

A help will be appreciated!

Thank-you.


Solution

  • After searching around, I found the solution for this.

    So I thought I would answer my own question.

    Flutter updated the function and we just have to use settings.name instead of settings.isInitialRoute

    class MyCustomRoute<T> extends MaterialPageRoute<T> {
          MyCustomRoute({ WidgetBuilder builder, RouteSettings settings })
              : super(builder: builder, settings: settings);
    
          @override
          Widget buildTransitions(BuildContext context,
              Animation<double> animation,
              Animation<double> secondaryAnimation,
              Widget child) {
            if (settings.name == '/') {
                 return child;
            // Fades between routes. (If you don't want any animation, 
            // just return child.)
            return new FadeTransition(opacity: animation, child: child);
          }
        }