Flutter action multiple
Oct 14 2020
Je veux créer un bouton J'aime, qui fonctionne comme une bascule, la couleur changera pour le rendre aimé en appuyant sur l'action, et appuyez dessus à nouveau pour ne pas l'aimer. comment puis-je y parvenir?
Réponses
6 Akif Oct 14 2020 at 14:21
Vous pouvez utiliser un simple bouton comme celui-ci:
IconButton(
onPressed: () {
setState(() {
_isLiked = !_isLiked;
});
}
},
icon: Icon(Constants.crownIcon,
color: _isLiked
? Constants.orangeColor
: Constants.ligthGreyColor,
size: 15.0,
),
),
1 Yeldar.N Oct 14 2020 at 14:18
Vous pouvez utiliser ToggleButtons
ToggleButtons(
children: <Widget>[
Icon(Icons.ac_unit),
Icon(Icons.call),
Icon(Icons.cake),
],
onPressed: (int index) {
setState(() {
isSelected[index] = !isSelected[index];
});
},
isSelected: isSelected,
),