Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
321 views
in Technique[技术] by (71.8m points)

Display an Alert Dialog when Futuredelayed time is finished in Flutter

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?

question from:https://stackoverflow.com/questions/65935915/display-an-alert-dialog-when-futuredelayed-time-is-finished-in-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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')
            ],
          ),
        );
      },
    );
  });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...