Make custom transition transparent so we dont need a 'background'

This reduces the animation overhead and cleanup the code.
This commit is contained in:
Ricardo Markiewicz
2019-07-02 10:02:37 -03:00
parent a9453903e8
commit 8ab8692bbb
4 changed files with 19 additions and 26 deletions
+5 -6
View File
@@ -2,14 +2,13 @@ import 'package:flutter/material.dart';
class AddPageTransition extends PageRouteBuilder {
final Widget page;
final Widget background;
AddPageTransition({this.page, this.background})
AddPageTransition({this.page})
: super(
transitionDuration: Duration(microseconds: 1),
pageBuilder: (context, animation1, animation2) => page,
transitionsBuilder: (context, animation1, animation, child) =>
Stack(
children: <Widget>[background, child],
));
transitionsBuilder: (context, animation1, animation, child) => child);
@override
bool get opaque => false;
}
+12 -8
View File
@@ -22,12 +22,18 @@ class MyApp extends StatelessWidget {
onGenerateRoute: (settings) {
if (settings.name == '/details') {
DetailsParams params = settings.arguments;
return MaterialPageRoute(
builder: (BuildContext context) {
return DetailsPage(
params: params ,
);
}
return MaterialPageRoute(builder: (BuildContext context) {
return DetailsPage(
params: params,
);
});
} else if (settings.name == '/add') {
Rect buttonRect = settings.arguments;
return AddPageTransition(
page: AddPage(
buttonRect: buttonRect,
),
);
}
},
@@ -45,5 +51,3 @@ class MyApp extends StatelessWidget {
);
}
}
+1 -2
View File
@@ -39,7 +39,6 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
CurvedAnimation(parent: _controller, curve: Curves.fastOutSlowIn));
_controller.addListener(() {
print(_controller.value);
setState(() {});
});
_controller.addStatusListener((status) {
@@ -285,7 +284,7 @@ class _AddPageState extends State<AddPage> with SingleTickerProviderStateMixin {
"year": today.year,
});
Navigator.of(context).pop();
_controller.reverse();
} else {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("Select a value and a cagtegory")));
+1 -10
View File
@@ -90,16 +90,7 @@ class _HomePageState extends State<HomePage> {
onPressed: () {
buttonRect = RectGetter.getRectFromKey(globalKey);
print(buttonRect);
var page = AddPageTransition(
background: widget,
page: AddPage(
buttonRect: buttonRect,
),
);
Navigator.of(context).push(page);
Navigator.of(context).pushNamed('/add', arguments: buttonRect);
},
),
),