Is there a way to access variables from different screen in flutter? What I am trying to do is i've been trying to perform a basic calculation but it won't let me since one of the variable that I am trying to calculate is defined from the other screen. Here is my code:
double amount = 0;
Center(
child: FlatButton(
onPressed: () {
setState(() {
balance += amount; // here is where I get an error since balance is not define from this screen it was define from the other screen. My plan is to add the current balance from the amount that came from the user and update that output base on this result.
});
},
child: Text(
"Continue",
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Color.fromARGB(255, 0, 0, 0)),
),
Here is my other code from the different screen:
double balance = 0;
child: Center(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Text(
"Current Balance: $balance", // This is where I want to display the output base on the calculations I have done on the other screen.
style: TextStyle(fontSize: 35, fontWeight: FontWeight.bold),
),
),
),
),
setState()to display the newbalancevalue.