1
I am passing values from one screen to another, by clicking a button on the home screen send the data to my profile. But if I do not click this button and go to my profile screen the fields referring to the values are returning me NULL. I wish they’d start with Zero but I’m not getting it.
Screen profile.Dart
class ProfilePage extends StatefulWidget {
final int valueScore;
final int valueLifes;
ProfilePage({Key key, this.valueScore, final int valueLifes;})
: super(key: key);
}
Further down in the same profile.Dart file I call these values to be shown on screen.
Text('${widget.valueScore}'),
Text('${widget.valueLifes}'),
In the.Dart home I have the following setting
class _HomePageState extends State<HomePage> {
int score;
int saveLifes;
void increment(){
setState(() {
score+=10;
saveLifes+= 3;
});
}
Still in the same.Dart home file, I have the button that calls the function to increment the value and pass the data to the profile screen
increment();
Navigator.of(context).push(
MaterialPageRoute (builder: (BuildContext context) =>
ProfilePage(valueScore: score, valueLifes: saveLifes,)),
);
If you can help in another detail, whenever I click on the button it passes the data to the profile screen and calls it without the user having clicked, I would like you to just pass the data and then when the user wanted to go there check.