flutter showdialog setState() or markNeedsBuild() called during build

After a bit research i understood that the problem is occuring becuase functions widget building causing problems as there is an already a build event occuring so i made the function asycn and it is working now.

Here is the code:

  _showMaterialDialog(String type) async{
    if(type=="win"){
      gameResult = "You Win, Gratz!";
    }else if(type=="lose"){
      gameResult = "You Lose :(";
    }
    print("buraya girdi");
    print(gameResult);
    await Future.delayed(Duration(milliseconds: 50));
    showDialog (
        context: context,
        builder: (_) => AlertDialog(
          title: Text("Result"),
          content: Text(gameResult),
          actions: <Widget>[
            FlatButton(
              child: Text('Close'),
              onPressed: () {
                  Navigator.pushNamed(context, HomeScreen.id);
              },
            )
          ],
        ));
  }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top