Is there any tool in Flutter that allows you to perform any function only on the selected day, month, year and time? - flutter

I'm developing an application in Flutter for online queries and right now I'm lost as to how to show the user, for example, a message based on the exact time he previously chose. The user can already choose the day, month, year and time, and after he selects them, I can store them as Strings, but I don't know of any tool that can perform some function at that exact moment. What I want to do is that after entering the information of the day and time of the consultation, a notification appears to the user asking him if he wants to join the video call, but only at the time he chose.
I tried to calculate the difference between the chosen date and the current moment, and based on that duration I used the Timer to execute some task after the elapsed time. But I was also in doubt if this function would be executed even if the user had not opened the application, so I don't know if it would really work or not. Previously I also researched dependencies that could help, I found for example the sf_calendar, but from what I observed it only has a system to choose the date and save and display this data on the screen, but it does not allow performing some function on that date.

Related

Pedometer with Daily steps counter using flutter

I am trying to build a basic fitness app using flutter.
The app has two main features:
Daily steps counter
graph of historical data (number of steps each day)
I use the pedometer plugin to retrieve data from the sensors of the phone.
My problem is that the plugin can only send the continuous step counting since the last reboot
that means if the user does not open my app for serval days, I don't know how many steps he walked each day only the total number of steps he did. I thought about letting my app run in the background but it will be a waste of battery
P.s I read Implementing pedometer in flutter article by Masky, but it is not solving my problem.
Thanks for any kind of help :)
Excerpt from: https://hub.packtpub.com/step-detector-and-step-counters-sensors/
The event timestamp represents the time at which the last step was taken. This sensor is especially useful for those applications that don’t want to run in the background and maintain the history of steps themselves. This sensor works in batches and in continuous mode.
Of the returned SensorEvent, the 1st value represents the number of steps since the last boot and it also contains a timestamp which is the amount of nanoseconds elapsed from the time of last device boot.
This site advises to use JobScheduler to "schedule periodic job to retrieve the total step count under suitable interval."
On the first site it explains how to maintain step history in case that's what you want, there's also sample code there.

onCalculate 24-hours or Date Change in Delphi

In my Delphi Windows application i need to login every day.
at first i used system date (11-11-2019) and i compare system date to stored one every time on OnCreate if date is different i call login.
But the system time can be paused right ? Then i thought of server time but checking server time on every OnCreate is not efficient i think as my app launches many times.
Can't use token based system to check as i am using firebase REST-API backed and it's token is expired in every one hour however if i use token based i still need to compare it and the system time might be paused.
How to effectively check if date is changed ?
The inapp time is short as the work is done in 10 seconds and the form may be then closed by user and the next app start time may be less a minute so why call for the server time again ?
You can check the current date and time querying a NTP server.
See this answer for more details.

Executing a specific method daily in Swift

I was wondering how you would go about having a function that executes once a day. In my case I would like users to answer a daily question and the answer will stay with the user for a day. The next day, a new question will be asked and so on. I've been told that you cannot execute functions when the user is not using the app. So I was wondering if there is a way to set a timer (e.g. a 24-hour) that expires and essentially deletes the answer? If there is any way you would go about this issue, I would really appreciate learning form you guys.
Currently I am using Parse.com to retrieve my questions and I am unsure whether or not I should save the answers back in parse or have them as NSUserDefaults because I don't know how to go about the issue stated above.
There are a couple of approaches:
Local notifications: You can schedule a local notification that (if the user grants notification privileges to the app) will present a notification to the user at some predetermined time. If the user taps on the notification, the app will be opened. (If the user doesn't tap on the notification, though, the app will not be opened.)
See Local and Remote Notification Programming Guide.
Background fetch: You can have the app request background fetch capabilities, in which the OS will allow the app to make very quick network requests to see if there is any data to retrieve. You can combine this with local notifications to let the user know when there is new question available. Note, you cannot control the timing of this, so it's not guaranteed to take place daily, much less at a consistent time every day. Nonetheless, this is an easy way for the app to check for new data without the user having to run the app themselves.
See Fetching Small Amounts of Data Opportunistically in the App Programming Guide for iOS.
Related to the local notifications, you could also entertain using push notifications (where your web service would proactively notify the user when there was new question available). This push notification service is discussed in the aforementioned Local and Remote Notification Programming Guide.
When the user starts up the app, you can compare the current date and time to the date and time associated with the last known question to see whether you present the last question or whether you initiate network request to get the next one.
Regarding where to store the answers, NSUserDefaults is almost certainly the wrong place. If you want to save it locally, save it to persistent storage (an archive or the like) or use Core Data. Saving it back to the network has the virtue, though, of the possibility to synchronize the state of the app's questions and answers across devices.
You could do it either way (saving it in Parse or NSUserDefaults). As for presenting a question once a day, you'd need to first make sure you timestamp once every time the user answers a question, then check if your last timestamp is greater than 24 hours.
So, you'd (roughly) say something like this:
Obj-C:
const uint DAY_IN_SECONDS = 24 * 60 * 60;
if (fabs([lastTimeTheUserAnsweredTimestamp timeIntervalSinceNow]) > DAY_IN_SECONDS) {
// present today's question.
} else {
// you've already answered today's question.
}
Swift:
let DAY_IN_SECONDS = 24 * 60 * 60;
if (fabs(lastTimeTheUserAnsweredTimestamp.timeIntervalSinceNow()) > DAY_IN_SECONDS) {
// present today's question.
} else {
// you've already answered today's question.
}
This of course assumes lastTimeTheUserAnsweredTimestamp is an NSDate.

Storing daily data in a mongoDB database using Parse

What would be the best way to store daily health related data (height, weight, calories burned, hours of sleep) in a Parse (MongoDB) database? The user will update their health data up to 10-15 times a day and I am unsure how to track their data in real time without having to create a new record every time they update only a certain piece of information. Currently I have a User class and a HealthProfile class, which contains basic information about height, weight, etc.
I could collect the data over the course of the day and then save it in the database at night however this will not work for database driven charts I want to display.
Data Interaction will be as follows: throughout the day a user inputs how much exercise they did, food they ate, etc. and the app will display a line/bar chart showing their progress/calories burned (or other health figures) for the day, week, and month. It will also include things like blood pressure and other measurements and I want to be able to store all of these things for a user and allow them to view their history, as well as input new data, at any time. It is a similar concept to how Apple's Health app works.
I will need to make sure the user's data is always persisted in a database so if they login on their phone or the website, their data is always up to date, so writes to the database will need to be upon user input and reads will take place any time the user view a chart or figure.
You really need to work out how you want to interact with the data. That will determine the best way to store it.
Once you have a clear picture of the different ways you want to read/write/use the data come back and ask clear questions to get help... currently it isn't clear what sort of help you want.

How to make a demo game in Unity3d?

I have developed a game in unity3d for pc and mac. I want to publish the game with 30 days trial period.
How do I make it? How do I write into the system registry. What things that I should keep in mind while developing this trial version.
Whenever I search in google, I get trial version of unity3d not about how to make a trial game in unity3d.
The following article has a lot of information, but is pretty long.
Writing to Registry
Regarding saving to the registry, only do this if you have a big game and will be writing other values to the registry. If it's just a small indie game, then rather avoid the registry. People don't like it when small indie games write values into their registry, as most developers will never remove that value.
There are 2 ways. You could either make the user "login" to your server every time, also called "Online Validation". This way is more secure, but does require the user to login which is not ideal. You could use the following offline method. Please note that I just thought about this, so there might be small flaws.
Offline Method
You could get the current system date and time. Encrypt the date and time and save it to disk. Then every time the game starts up, get the system date and time again and check this "new" time to the date and time you have stored on disk. This check will more be to make sure the user has not modified the system date and time. Obviously overwrite the date and time every time the game is started, but obviously first check the value.
You'll know if the user has modified their time if the "new" date and time you got is not more than the old stored date and time. You could also get the date and time, just before the game exits. Then when the game starts up again, you can make sure that the current date and time is more than the date and time you stored to disk.
Also get the date and time when the game first starts up and save that. As you can then check exactly how many days until their trial runs out.
What you should keep in mind
Allow the user to keep their saved game (if they can save). So that when the buy your game, they do not have to start all over again.