I want to show the card on the main page Once a week in my app. can anyone help me how can I do that?
by the way, I use Future.delayed
in the init state and set duration day 7 for it.
but I think it is wrong.
so how can I do that?
void initState() {
Future.delayed(Duration(days: 7), () {
showBottomSheet(context);
});
super.initState();
}
CodePudding user response:
You can do one thing
get weekday and set a condition on that like
DateTime date = DateTime.now();
print("weekday is ${date.weekday}");
if date.weekday == MONDAY {
do task for Monday
}else {do task for other day.. }
this will very simple and easy away to trigger event on a specific day like sale on frieday or movie offer on Sunday..
CodePudding user response:
Try to use Timer.run
refer Timer
,
@override
void initState() {
super.initState();
Timer.run(() {
Future.delayed(Duration(days: 7), () {
showBottomSheet(context);//This function display after every 7 Days
});
});
}