Home > Blockchain >  how to display a page with a certain duration when click the button before goback in Flutter
how to display a page with a certain duration when click the button before goback in Flutter

Time:09-14

How to display a page with a certain duration when click the button before goback in Flutter.

This is my code:

                    onPressed: () {
                        Future.delayed(const Duration(seconds: 2))
                            .then((value) {
                          Navigator.push(
                            context,
                            MaterialPageRoute(
                              builder: (context) => SuccessMessage(
                                  title: "Ubah Password Sukses!",
                                  subtitle:
                                      "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Consectetur adipiscing elit."),
                            ),
                          );
                        });

                        Navigator.of(context).popUntil((_) => count   >= 3);
                      },

CodePudding user response:

Below is the code to navigate or go back after a few seconds hope it work for you

Future.delayed(Duration(seconds: 2), () {
  //Here you can put your code which executes after 2 seconds
});

you can change seconds based on your requirement. You have used .then after Delayed which is not required

CodePudding user response:

Use await on your Future.delayed

onPressed: () async {
  await Future.delayed(Duration(seconds: 2), () {
     Navigator.push(
        context,
        MaterialPageRoute(
          builder: (context) => SuccessMessage(
            title: "Ubah Password Sukses!",
            subtitle: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Consectetur adipiscing elit."),
         ),
     );
  });
  Navigator.of(context).popUntil((_) => count   >= 3);
},
  • Related