I'm using flutter for the web.
The page is transitioning with Navigator.of(context).pushNamed(Home.route);
, but the animation is played at this time.
Is it possible to disable this animation?
I wrote the following code in the main()
function of main.dart
.
MaterialApp(
initialRoute: '/home',
routes: {
'/home': (context) => Home(),
'/profile': (context) => Profile(),
},
@immutable
class Home extends StatelessWidget {
static const String route = '/home';
....
}
@immutable
class Profile extends StatelessWidget {
static const String route = '/profile';
....
}
And as I mentioned earlier, the following code is used to transition the page.
Navigator.of(context).pushNamed(Home.route);
I was able to transition pages without animation by using Navigator.push
, but I want to use Navigator.of(context).pushNamed()
because the link does not change.
Does anyone know how to disable animation while still using Navigator.of(context).pushNamed()
?
Thank you.
I solved this problem.
I didn't use Navigator.of().pushNamed()
but, it is possible to show URL of pages.
first, I removed routes:
from MaterialApp()
and added onGenerateRoute:
like this;
onGenerateRoute: (settings) {
Widget wid = Home();
switch (settings.name) {
case "/home":
wid = Home();
break;
case "/profile":
wid = Profile();
break;
}
if (wid != null) {
return PageRouteBuilder(
settings:
settings, // Pass this to make popUntil(), pushNamedAndRemoveUntil(), works
pageBuilder: (_, __, ___) => wid,
transitionsBuilder: (_, a, __, c) =>
FadeTransition(opacity: a, child: c));
}
// Unknown route
return MaterialPageRoute(builder: (_) => Home());
},
And when you want to move page, just call this;
Navigator.of(context).pushReplacementNamed('/home');
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