[Résolu] Problème d'interactivité

import ‹ package:flutter/material.dart ›;

class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}

class _HomeState extends State {
bool displayIt = true;
var _score = 0;
var voila = « voilà 0 clic »;
_restartOnPressed() {
setState(() {
displayIt = true;
print(« réinitialisé »);
_plusButtonClicked();
});
}

_plusButtonClicked() {
setState(() {
_score++;
if (_score == 0) displayIt = true;
if (_score > 1) voila = « voilà $_score clics ! »;
if (_score < 2) voila = « voilà $_score clic ! »;
if (_score > 10) {
displayIt = false;
_score = 0;
}
print(« plus ou non »);
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(voila),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (displayIt == true)
IconButton(
icon: Icon(Icons.add_circle_outline),
iconSize: 48,
onPressed: _plusButtonClicked),
if (displayIt == false)
ElevatedButton(
onPressed: _restartOnPressed(), child: Text(‹ restart ›)),
],
),
],
),
);
}
}

Ce code ne marche pas, ou juste un peu : il crée un clicker jusqu’à 11, et ensuite fait apparaître un bouton « Restart » qui, lui ne fonctionne pas du tout. Ce qu’il y a de bien, c’est qu’il apparaît, mais bon, il ne redémarre pas le clicker… Pourquoi ?

// problème résolu :
import ‹ package:flutter/material.dart ›;

class Home extends StatefulWidget {
@override
_HomeState createState() => _HomeState();
}

class _HomeState extends State {
bool displayIt = false;
var _score = 0;
var voila = « voilà 0 clic »;

_plusButtonClicked() {
setState(() {
_score++;
if (displayIt) {
_score = 0;
}
if (_score == 0) displayIt = false;
if (_score > 1) voila = « voilà $_score clics ! »;
if (_score < 2) voila = « voilà $_score clic ! »;
if (_score == 11) {
displayIt = true;
print(« tac »);
}
print("$_score");
});
}

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(voila),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (displayIt == false)
IconButton(
icon: Icon(Icons.add_circle_outline),
iconSize: 48,
onPressed: displayIt ? null : _plusButtonClicked,
),
],
),
if (displayIt == true)
ElevatedButton(
child: Text(« restart »),
onPressed: displayIt ? _plusButtonClicked : null,
style: ElevatedButton.styleFrom(
primary: Colors.red,
onPrimary: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32.0),
),
),
)
],
),
);
}
}