Can I create a background service that always run even if flutter app is not running? - flutter

I want to create a Background service which is always running even if app is not running in background , so that I can manage different features in my flutter , is there any way to do that?

There are several ways of doing this.
You can check out flutter_background_service. It's a new package.
background_fetch is another package that can help you out.
Additionally if you're only planning to execute a task when you get some new information from a remote server, firebase data message can be used too, where you'll run a function upon receiving a data message. link

Related

How to send data from background service to main application in flutter

I am running a background servie and at a specific time, I want to send some data in form of JSON string to my application. It may happen that my app is currently terminated, so I am using app laucher plugin to open my application. After opening the application, I want to send some data to application so as to display it. So, how can I send the message and recieve it in my main application (I will have to change the state of my widget once I recieve the data)?
I am not completely sure if this works, but I think instead of somehow sending the data from the background service to the main application you could probably save it in shared preferences or local database or using hive or something similar and simply retrieve it in your main application.
Definitely agree with above answer , But if you want to secure your application more then you can use Flutter_Secure_Storage. It is alternative to Shared_Preference :)

how to Store app data and prevent data to get lost and also make app work at background in flutter

I am a intermediate flutter developer and working on my first commercial app And I have almost created whole app ui but problem is when i close my app all data get lost . so how can i prevent it + how can i make my app work at background when app is close like in clock app . In clock app even if app is closed then also we get alarm at the timing we set . It is not possible to provide whole app code thats why i am explaining it in words . Hope you guys will understand the problem and provide best answer .
You can use internal data base concept to save user data like JWT key , user id, first name ,last name or app content for offline usage like blog articles ,pos system data for offline usage
Use Shared preferences to save basic data like user data, JWT but less secure
but if you need save complex data and need query or filter you can use hive and you can keep data more secure
And Alarm is totally deferent approach,
when we schedule alarm,alarm manager schedule task on system alarm services and wakeup app with intent and flutter Isolate class
We divide your question into two parts.
Question 01: How to store data locally :
You can use key-value storage like Shared preferences, Hive
If you are familiar with SQL you can use SQLite
If you are familiar with NoSQL you can use database like sembast
These are some of the popular databases that you can use with flutter. And much more available at pub.dev. But you want to use a database with your task. As an example simply store the user name or user id you can use Shared preferences
Question 02: Make Alarm Application :
For android applications, you can simply use android_alarm_manager
I suggest you take a deep look at the flutter docs about the subject:
Background processes
To run background processes continuously, take a look at this
package: https://pub.dev/packages/background_fetch
If you need to show scheduled messages, use local notifications:
I think by referring to these links you can get an idea.
To store data locally you can use local storage options like Database such as SQFlite, Hive etc or SharedPreference that will save your data locally and to run background process you need to use MethodChannel and write platform specific code or you also have the options to use Isolates. You may read more using this link
https://docs.flutter.dev/development/packages-and-plugins/background-processes

Create an order using transactions API

I'm trying to create a simple order using transactions API on actions on Google, for this, I'm using this sample app, but when I try to place the order, the device times out, instead of showing the receipt details. The weird thing is that this code gets executed (I added some logs locally to make sure).
Has anyone been able to run this sample app successfully? I already enabled the actions on Google API on my project on Google cloud, so I'm not sure what I'm missing here.
First, you got to make sure you have enabled transaction support for your app.
If you are testing on the simulator, disable Sandbox mode (checkbox on top right).
Sandbox ensures that any transactions or orders made during simulation are fake
I've ran into this issue before.
You have to keep in mind that the Order ID gets tracked so it needs to be different every time you run the app. That is why I decided to use a UUID time stamp function to make sure the Order ID will be different every time.
I'm referring to wherever it mentions 'UNIQUE_ORDER_ID' in the code. Once you take care of this issue, you will see the receipt every time you run the demo.

Azure WebJob Logging/Emailing

I've converted a console app into a scheduled WebJob. All is working well, but I'm having a little trouble figuring out how to accomplish the error logging/emailing I'd like to have.
1.) I am using Console.WriteLine and Console.Error.WriteLine to create log messages. I see these displayed in the portal when I go to WebJob Run Details. Is there any way to have these logs saved to files somewhere? I added my storage account connection string as AzureWebJobsDashboard and AzureWebJobsStorage. But this appears to have just created an "azure-webjobs-dashboard" blob container that only has a "version" file in it.
2.) Is there a way to get line numbers to show up for exceptions in the WebJob log?
3.) What is the best way to send emails from within the WebJob console app? For example, if a certain condition occurs, I may want to have it send me and/or someone else (depending on what the condition is) an email along with logging the condition using Console.WriteLine or Console.Error.WriteLine. I've seen info on triggering emails via a queue or triggering emails on job failure, but what is the best way to just send an email directly in your console app code when it's running as a WebJob?
How is your job being scheduled? It sounds like you're using the WebJobs SDK - are you using the TimerTrigger for scheduling (from the Extensions library)? That extensions library also contains a new SendGrid binding that you can use to send emails from your job functions. We plan on expanding on that to also facilitate failure notifications like you describe, but it's not there yet. Nothing stops you from building something yourself however, using the new JobHostConfiguration.Tracing.Trace to plug in your own TraceWriter that you can use to catch errors/warnings and act as you see fit. All of this is in the beta1 pre-release.
Using that approach of plugging in a custom TraceWriter, I've been thinking of writing one that allows you to specify an error threshold/sliding window, and if the error rate exceeds, an email or other notification will be sent. All the pieces are there for this, just haven't done it yet :)
Regarding logging, the job logs (including your Console.WriteLines) are actually written to disk in your Web App (details here). You should be able to see them if you browse your site log directory. However, if you're using the SDK and Dashboard, you can also use the TextWriter/TraceWriter bindings for logging. These logs will be written to your storage account and will show up in the Dashboard Functions page per invocation. Here's an example.
Logs to files: You can use a custom TraceWriter https://gist.github.com/aaronhoffman/3e319cf519eb8bf76c8f3e4fa6f1b4ae
Exception Stack Trace Line Numbers: You will need to make sure your project is built with debug info set to "full" (more info http://aaron-hoffman.blogspot.com/2016/07/get-line-numbers-in-exception-stack.html)
SendGrid, Amazon Simple Email Service (SES), etc.

Google.GData.Documents.DocumentService.Query() hangs in multithreading

I am tying to download documents of multiple users simultaneously using threading.
The application download documents for some users and eventually all the threads get stuck at the following statement.
Google.GData.Documents.DocumentService.Query()
However if I try to download them one user after the other (no threading). It downloads just fine. Every thread has its own instance of DocumentFeed, DocumentsListQuery,Document Service etc
The application is developed in c#. What could be the possible reason for it to get stuck on the "query()" statement?