Reputation: 123
I want to pass data from page1 to page2 using PageRouteBuilder(for animation matters), problem is how to pass it. I don't to sacrifice my animation by using MaterialPageRoute().
/// My button in page 1
Listview.builder(
...
...
...
onTap: () {
Navigator.of(context).push(_createRouteSelectType(12)); //data i want to pass
},
),
/// My PageRouteBuilder
Route _createRouteSelectType(buCode) {
return PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => page2(buCode),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
var begin = Offset(0.0, 1.0);
var end = Offset.zero;
var curve = Curves.decelerate;
var tween = Tween(begin: begin, end: end).chain(CurveTween(curve: curve));
return SlideTransition(
position: animation.drive(tween),
child: child,
);
},
);
}
/// My page 2 class / receiver
import 'package:flutter/material.dart';
class page2extends StatefulWidget {
final int buCode;
page2({Key key, @required this.buCode }) : super(key: key);
@override
_LoadT createState() => _LoadT();
}
Upvotes: 2
Views: 263
Reputation: 4109
Give this package a shot: auto_route, it:
Upvotes: 1