Make custom transition transparent so we dont need a 'background'
This reduces the animation overhead and cleanup the code.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
+9
-5
@@ -22,12 +22,18 @@ class MyApp extends StatelessWidget {
|
||||
onGenerateRoute: (settings) {
|
||||
if (settings.name == '/details') {
|
||||
DetailsParams params = settings.arguments;
|
||||
return MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
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 {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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")));
|
||||
|
||||
@@ -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);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user