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.
The isInitialRoute property in RouteSetting has been deprecated. Read more here.
Instead you can do:
MaterialApp(
initialRouteName: ‘yourRouteName’,
Or:
onGenerateInitialRoutes: (String initialRouteName) {
return <Route>[YourRoute()];
}
Please note that your initialRoute
is the first route in Navigator
. It refers as /
. So, if you want you can do this also: settings.name == '/'
.
After searching around, I found the solution for this.
So I thought I would answer my own question.
Flutter updated the function ans 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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With