Push transition animation

Transition animation rewrite the code:

import 'package:flutter/material.dart';

class CustomRoute extends PageRouteBuilder {
final Widget widget;
CustomRoute (this.widget) // override the constructor method call this method directly call ---- is this method is similar to override the init widget pass over here because this is the page class is overridden methods Yazhan
:super(
transitionDuration: Duration (seconds: 1), // transition time
pageBuilder: (// constructor page
BuildContext context, // context
Animation <double> animation1,
Animation <double> animation2,

){
return widget;
},
transitionsBuilder: (// constructor transition, the main implementation
BuildContext context,
Animation <double> animation1, // animation guess is the parent page
Animation <double> animation2, // guess is animated subpages
Widget child // subfolders
)
{
// animation in
return FadeTransition(
opacity: Tween (begin: 0.0, end: 1.0) // alpha transparency effect similar
.animate(CurvedAnimation(
parent: animation1, // default is animation1
curve: Curves.fastOutSlowIn // animation curves slow down after, a slow-fast-forward
)),
child: child, // incoming subpages
); // fade fade
}
 
);
}
 
Use Code:
import 'package:flutter/material.dart';
import 'second_page.dart';
import 'custom_route.dart';
class FirstPage extends StatelessWidget {
const FirstPage({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: AppBar (
title: Text('First Page',style: TextStyle(fontSize: 36.0)),
elevation: 1.0, // default floating layer effect 4.0 Navigation Bar
),
body: Center(
child: MaterialButton(
child: Icon(
Icons.navigate_next,
color:Colors.white,
size:64.0
),
onPressed: (){
Navigator.of(context).push(CustomRoute(SecondPage()));
}
),
),
);
}
}
to sum up:
 

 

// transition animation

Rewrite PageRouteBuilder {

transitionsBuilder () // transition constructor {

return FadeTransition {// transition Method

// alpha changes

opacity:Tween(begin:xx,end:xxx).animate(CurvedAnimation

){

curve: Curves.fastOutSlowIn // animation curves slow down after , a slow-fast-forward 

 

}

 

}

 

}

 

 

}

 

navigation

elevation: xxx navigation bar floating layer effect 0 is no effect embedded into the page, default 4.0

appbar

leading: Container (), // font center 

Guess you like

Origin www.cnblogs.com/pp-pping/p/12180057.html