Text widget doesn't appear in dialog after user Future.delayed in Flutter


I have a dialog that appears after user click on send button . When dialog appears , I want to show a text after 5 seconds . I use Future.delayed but the text doesn’t appear at all . It appears only when I close the dialog and open it again . I want to show the text after 5 seconds from opening the dialog .

Here is my function

  void _initialize() {
    Future<void>.delayed(const Duration(seconds: 3), () {
      if (mounted) {
        setState(() {
          visibility = true;

And here is my dialog code in the onTab of the button

 showDialog(context: context,
        barrierDismissible: false,

        builder: (BuildContext contextd){

          return  WillPopScope(

            onWillPop: () {return Future.value(false);},
            child: Dialog(
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10)
              child: Padding(
                padding: EdgeInsets.fromLTRB(20.w, 20.h, 20.w, 20.h),
                child: Column(
                        children: [
                       //here are some widgets
                        child: Text("Resend?",style: TextStyle(decoration: 



Try using StatefulBuilder like this:

        context: context,
        builder: (BuildContext context) => StatefulBuilder(
          builder: (context, setState) {
            return //somthing to return;

Answered By – Siddharth Mehra

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *