How to set remainder countdown by getting values from database in flutter - flutter

In this screen I am creating ride, and taking all these information include (Date and Time of ride) from the driver. After creating a ride I am saving all the data into firestore and getting data into next screen. I am also pasting the screenshot of next screen below
I want to show the countdown according to the date & time and when the countdown end, the start button will enable. how can we do it ? Kindly help me

First of all you have to get difference of time. Start countdown timer with that time. Once you get zero you can enable start button based on that condition. You can see this solution.

Related

How do i record stopwatch times in flutter

I would like to know how i can get the ending stopwatch time string once i have stopped the timer. I'm using this repo to make my stopwatch. Once i have stopped the timer i want the timer that is displayed to be put in a list so that i can record my times on a page like this:Times page. Would it use the If/else function?
Thanks Hunter

Swift 3: UIButton re-enables after midnight

I have a button which disables after it is pressed. I need To work out how to get the button re-enable after midnight, or the next day.
So I think I need the button to set the date in a variable after it is pressed. Then an if statement which enables the button if the variable does not match today's date.
Would that be the best way to handle it? Can anyone offer any rough code advice, or possibly advice of an easier way to handle enabling a button after midnight?
Thanks
Then an if statement which enables the button if the variable does not match today's date.
But the question is, an if statement where? Your code can only run if something makes it run. If your app is just sitting there, midnight can come and go and your button won't be enabled because the code that looks to see if it's a different day from the day you saved is not running.
The solution:
Register to be notified by the system when the day changes.
Woow finally some nice question... it's definitely possible... you can check this beautiful documentation by apple:
https://developer.apple.com/library/content/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Basically you have 2 or more solutions, just 2 comes to my mind right now:
1.) Use UserDefaults or CoreData (Userdefaults for one property is more acceptable I guess
2.) Run backgroundTask as mentioned above..
The first one is very basic solution... you get the date when the button was tapped and if the day is equal to the day you entered the screen later, you keep the button disabled, else you unlock the button and store again the date into the user defaults, this seems to me a little piggy if you ask me..
The second one is much more elegant, in a nutshell... You setup button with some actions and the last thing is disabling it. Then, you setup background Task that every next day the button becomes enabled again...
I am pretty sure you will find the codes somewhere else here, maybe you will find the first algorithm more useful for you..
Anyway wish you best luck and happy coding! :)

How to implement a counter with CloudKit?

Situation
I want to manage a counter (the number of times of button is pressed) with CloudKit.
Each time a user press a button, I want to increment an integer. This integer will hence be a global (for all users) counter of how many times the button has been pressed.
Question
Is there a preferred way to do it?
My idea
I could store a CKRecord with this number and fetch and modify it each time the button is pressed. But, isn't it unsafe since it might be updated by many people (more or less) at the same time?
Your idea would work. When doing an update you will first fetch the counter record, increment the counter and then save it back. If another user has updated the counter in the mean time, then CloudKit will give you an error and you can try it again.
But it does depend on how often users will press the button. If you have multiple pushes per second during a longer period, then you will probably get a lot of errors when updating the data. The time before an update succeeds will grow.

3hr Time delay between a button press

I would like to create a daily event, that is activated with a button press. So i would like to create a 3hr timers that disables the button once it has been pressed for 3hrs.
Im assuming i would use a NSDate code, but I'm unsure how the coding would go..
thanks.
This is how I would accomplish such a task:
1st button press - run event, capture current linux time. Example : 1332823536
add 10800 (which is 3 hours) which would make our example: 1332834336
save this number as an integer to NSUserDefaults
when the app starts back up check current time, turn it into an integer and make sure the current time is equal to or greater than the time you last saved (when the button was pushed)
if its NOT greater, disable the button - if it IS greater, enable the button.

Reason for 5 sec delay to show an activity on pressing the home button?

I am facing delay of 5 sec to show an Activity after pressing the HOME key. I had gone through some post and found that after pressing the HOME button, android prevents services and broadcast-receivers from calling startActivity for 5 seconds.
Q1. Can anyone please let me know the reason to happening this delay ?
Q2. When I modified the ActivityManagerService::checkAppSwitchAllowedLocked() to always return true, it avoids checking lock and hence Activity gets shown without any delay. Would it be a good solution to avoid delay or it may cause any wrong effect in other ways ?
I know, it's probably too late (half year passed). However, here is the answer
You won't be able to get this permission on not rooted phone, unless your application is signed with the same keys as system. Android has some permissions like that.
Also, you may be interested to check this question. Starting an activity from a service after HOME button pressed without the 5 seconds delay