I have an alertDialog which have duration of 8 second and I want to disaply another one when this time is finished automaticaly this is my code:

 Future.delayed(Duration(seconds: 7), () {
Navigator.pop(context);
});
return AlertDialog(content: Column(mainAxisSize: MainAxisSize.min,
children: [
Center(child: CircularProgressIndicator()),
Text('Attendi l\'invio del File')
],
),
);

at this stage when 8 second passed, I want to disaply another AlertDialog which confirm the uploading. Any Input?


Solution 1: Shubham Narkhede

  Timer _timer;

You have to call this show dialog on your button or where you want to call

    showDialog(
      context: context,
      builder: (BuildContext builderContext) {
        _timer = Timer(Duration(seconds: 5), () {
          Navigator.of(context).pop();    // == First dialog closed
        });

        return AlertDialog( 
          title: Text('First Dialog'),
          content: SingleChildScrollView(
            child: Text('Content'),
          ),
        );
      }).then((val) {
    if (_timer.isActive) {
      _timer.cancel();
    }
  }).then((value) {
    showDialog(
      // == Second dialog open
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Center(child: CircularProgressIndicator()),
              Text('Second Dialog')
            ],
          ),
        );
      },
    );
  });