Вы можете создать to
аргументы ...
Примерно так
class LoginWidgetArguments {
final String username;
LoginWidgetArguments(
{this.username});
}
class LoginWidget extends StatefulWidget {
@override
State<StatefulWidget> createState() => _LoginWidgetState();
}
class _LoginWidgetState extends State<LoginWidget>{
LoginWidgetArguments args;
@override
void initState() {
//Get context
// I do this because sometimes it doesn't get the context without the FutureDelay... This workaround I used with the first flutter versions, maybe now its not needed
Future.delayed(Duration.zero, () {
args = ModalRoute.of(context).settings.arguments;
if (args != null) {
print(args.username)
}
});
}
....
}
И для навигации
Navigator.pushNamed(context, LoginPage.routeName,
arguments: LoginWidgetArguments(
user: "user@yay.com");
Редактировать
Может быть, это может быть просто ...
FlatButton(
padding: EdgeInsets.fromLTRB(2, 5, 5, 5),
child: ListTile(
leading: Icon(Icons.book, color: Color(0xFFEB3549)),
title: Text('Book5'),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PDFPage(pageNumber: 6) ));
print('Pressed 6');
},
)
class PDFPage extends StatefulWidget {
final int pageNumber;
PDFPage({this.pageNumber});
@override
_PDFPageStage createState() => _PDFPageStage();
}
class _PDFPageStage extends State<PDFPage> {
...
@override
void initState() {
super.initState();
changePDF(widget.pageNumber);
loadDocument();
}
...
}