Reputation: 111
I have several register forms with next buttons and I would like to switch between the different screens with
onTap: () => { Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SomeOtherScaffold()))
},
but without the default animation that comes with it.
Upvotes: 3
Views: 3650
Reputation: 1151
In MaterialApp
theme: Theme.of(context).copyWith(
pageTransitionsTheme: PageTransitionsTheme(
builders: {
TargetPlatform.android : _NoAnimationTransition(),
TargetPlatform.iOS : _NoAnimationTransition(),
// if you have more you can add them here
}
)
),
create a PageTransitionsBuilder
class _NoAnimationTransition extends PageTransitionsBuilder{
@override
Widget buildTransitions<T>(_, __, ___, ____, Widget child) => child;
}
All navigation animations will be removed
Upvotes: 0
Reputation: 8978
If you want to use other animation, you can use transitionBuilder
, in your PageRoute
. How you can use this represented for you below:
import 'package:flutter/material.dart';
main() {
runApp(MaterialApp(
home: Page1(),
));
}
class Page1 extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: RaisedButton(
child: Text('Go!'),
onPressed: () {
Navigator.of(context).push(_createRoute());
},
),
),
);
}
}
Route _createRoute() {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => Page2(),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return child;
},
);
}
And if you want to transition instantly, you can do this:
transitionDuration: Duration(seconds: 0)
This will decrease down the transition time to 0 second, which will eventually results to quick transition speed.
To know more about Page Animation Transition
follow these articles:
You need to define something for your transition, if you don't want the default one, and this answer will help you achieve this.
Upvotes: 1