How to set a limit on button clicks 2 times a day?
I have a button
IconButton(
icon: Icon(Icons.arrow_forward_ios), onPressed: () async {
_CreatePost();
_showLoaderDialog(context);
},
),
and I want the button to be inactive for 24 hours when there are 2 clicks. How can I do this I would appreciate any help.
I tried to find information on many sites but there is very little information, I tried a lot of things but it does not help.
2
Answers
If i had this problem i would solve saving the datetime of last two clicks on shared preferences or any database that you prefer, and on build method i would check if the older click has more than one day. if not i would disable the button and make a future.delayed function to able this buttom on right time. After the two clicks on 24h you need disable the button and make a future.delayed function to able the button after 24h. Just make sure to cancel the future function when the user change screen. A example of how cancel future.delayed function is here.
You can save the last button press time to
shared_preferences
and you just have to calculate the time difference if it is more than 24 hours when you activate the button.