1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| class _MyHomePageState extends State<MyHomePage> {
// création des différents labels
List<String> _labelBtn = ["Bouton Un", "Bouton Deux", "Bouton Trois", "Bouton Quatre"];
List<String> _newlabelBtn = ["One", "Two", "Three", "Four"];
changeText(i, text) {
setState(() {
_labelBtn[i] = "Button $text";
// ou encore quelque chose comme
//_labelBtn[i] = _newlabelBtn[i];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
for (int i = 0; i < 4; i++)
RaisedButton(
color: Colors.green,
textColor: Colors.black,
child: Text(_labelBtn[i], style: TextStyle(fontSize: 21)),
onPressed: () => {
changeText(i, _newlabelBtn[i])
},
),
],
),
),
);
}
} |
Partager