Вот как я понял, взяв bool _button1Pressed и изменив его значение в методе setSate . Это правильный подход?
class Profile extends StatefulWidget {
@override
_ProfileState createState() => _ProfileState();
}
class _ProfileState extends State<Profile> {
bool _visible = true;
bool _button1Pressed = true;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Madelyn Johnson'),
centerTitle: true,
backgroundColor: Colors.grey,
),
Row(
children: <Widget>[
Expanded(
child: RaisedButton(
elevation: 1.0,
color: _button1Pressed ? Colors.pinkAccent : Colors.white,
onPressed: () {
setState(() {
_visible = true;
_button1Pressed = true;
});
print('pressed1');
},
child: Icon(Icons.dashboard),
),
),
Expanded(
child: RaisedButton(
splashColor: Colors.red,
elevation: 1.0,
onPressed: () {
setState(() {
_visible = false;
_button1Pressed = false;
});
Navigator.of(context).push(_ProfileToStory());
print('pressed2');
},
color: _button1Pressed ? Colors.white : Colors.pinkAccent,
child: Icon(Icons.favorite),
),
)
],
),
],
),
),
);}