I a trying to pass a Value from when a button is clicked, What I want in the code is to pass the value from the Button Widget to another Page's Variable named pdfNo. Here's my code:
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() ));
print('Pressed 6');
},
),`
This is the Button on the First Page , On Pressed I would like to pass a Value to a function which is child, so I have created a variable , but cant figure out how to go about this next:
var pdfNo = 2;
bool _isLoading = true;
PDFDocument document;
@override
void initState() {
super.initState();
changePDF(pdfNo);
loadDocument();
}
changePDF(value) async {
setState(() => _isLoading = true);
if (value == 1) {
document = await PDFDocument.fromAsset('assets/sample2.pdf');
} else if (value == 2) {
document = await PDFDocument.fromURL(
"http://conorlastowka.com/book/CitationNeededBook-Sample.pdf");
} else {
document = await PDFDocument.fromAsset('assets/sample.pdf');
}
setState(() => _isLoading = false);
}
So, I would like to pass a int from the button on page 1 Staleful Class to a Stateful Class on second page to changePDF(here).
Please help me out. PS New to Flutter,Dart