Flutter alert dialog setState not changing

ram*_*han 3 dart flutter

I am trying to change some bool values in my Dialog. I am doing like this

   showDialog(
      context: context,
      builder: (context) {
        return StatefulBuilder(
          builder: (context, setState) {
            bool testBool = true;
            return Dialog(
              shape: RoundedRectangleBorder(
                  borderRadius:
                  BorderRadius.circular(12.0),
                  side: BorderSide(
                      color:
                      kPrimaryColor)), //this right here
              child: GestureDetector(
                onTap: (){
                  print(testBool);
                  setState((){
                    testBool = !testBool;

                  });
                  print(testBool);
                },
                child: Container(
                  height: 525,
                  width: width * 0.85,
                  child:
                  Text('12313', style: TextStyle(color: testBool? Colors.red : Colors.green),),
                ),
              ),
            );
          },
        );
      },
    );
Run Code Online (Sandbox Code Playgroud)

But its not changing the color, I mean to say its not changing testBool state in Dialog.

Cop*_*oad 5

Your code is fine but you're putting the bool condition within the builder which is why every time you call setState it is again set to true.

showDialog(
  context: context,
  builder: (context) {
    bool testBool = true; // This flag should be here.
    return StatefulBuilder(
      builder: (context, setState) {
        // ... 
      },
    );
  },
);
Run Code Online (Sandbox Code Playgroud)