Home > Net >  Change the Page to another page in flutter at a specific date and time
Change the Page to another page in flutter at a specific date and time

Time:09-06

So I want my flutter application to navigate the user to a new page called home page at a particular date and time of that date this is my code can I change it to work not after 5 seconds but on Wed,7 Sep at 8:00 am

@override
void initState() {
Timer(
  Duration(seconds: 5),
  () => Navigator.of(context).pushReplacement(MaterialPageRoute(builder: (BuildContext context)=>GamePage())), 
);
super.initState();

CodePudding user response:

I guess you are looking for is notifications. You can make it work like...

  1. the backend sends a notification on this particular time
  2. if the app is active and receives this notification, you can navigate to the required screen
  3. If the app is inactive, the user will receive the notification and if he opens the app through notification, you can directly navigate them to the required screen.
  4. If he doesn't open the app through notification, you can simply check your required date and time with the current date and time, and navigate accordingly.

CodePudding user response:

Check if that day is equal to the Date and Time you want and then execute the timer function.

DateTime today=DateTime.now();
if(DateTime(today.year,today.month,today.day)==DateTime(2022,9,7,8,0)){
   //Timer function
}
  • Related