How to extract data from webserver to flutter app - database

how can I add an auto-update my code in a flutter? I am creating an app to check the market rate or wholesale rate of chicken, mutton, and seafood (all Alive) so I don't want to waste my time on copy-pasting the price every day. I want something that extracts data from a website and inserts it to my flutter app. that changes the price in all as thee prie on website changes. I also want to upload it to the play store.

Use an API to extract the data from whatever website you like and you can either set a timer which at regular intervals checks if the price has changed and updates if necessary or using an API will reload prices when the app is closed and opened again anyway.

Related

Is refreshing data every time duration to check for new orders in admin page bad?

I built an admin page in React.js to check for new orders placed, but I used a useEffect with setInterval for a specific duration (30 seconds for example) to keep on fetching new orders from the backend and mysql server.
Is this a bad pattern or not? Is the a better way , maybe to notify the admin that there are new orders then he will refresh manually?
Thanks!

Multiple API-requests in React HowTo

Starting to learn React and building a simple client for an API. On the startpage of the app, im listing paged data fetched from the api. And every "item" that is fetched is including a customerNumber. If i want to get the actual name of the customer, i have to make another request to the API with the customerNumber. And i need to show the customers name on every item on the page.
Is it ok to fetch the name separately for every single customer? The item-page could show 10-50 items per page and that should create an separate API-call for every one.
Or is there a better way to do this, when the API dont serve everything on the same endpoint?
Thanks!

Flutter + Global var or SQL?

So I need to have a few things store in either a var that is accessable by all widgets. or store things in a SQL and then get the widgets to check for the latest update.
Task I am trying to do.
I have 3 images at the bottom of my main_widget.dart each one when clicked on does the following:
Stop the current radio station music.
Start the radio station that the user click on.
Changes the now playing url to match the station. - this is a separate widget all together.
So can flutter do global var that store or should I use SQL and store the values in a table called
active:
Station URL
Station Now Playing URL
And then call this when the user opens and closes the app as well as when the user clicks on another station logo just update the active database to have the correct data?
Having SQL or any database kind method is not good for just make it available from all widgets. There is no need basically. You need some kind of global variable but of course there are better ways than global variables.
The concept is called state management. Start reading from official flutter website.
I recommend BLOC for most cases. Here is the main website of a good BLOC package for flutter apps. Created by Felix Angelov. https://bloclibrary.dev/#/
For saving the simple user data for closing/opening the app you can use shared preferences. But be aware it is not for storing sensitive data like tokens, credentials etc. Just use it for "simple" and "non-sensitive" data.

Continuous data save & reload - best practice

I've just started working on the financial web app which was implemented a few years ago in AngularJS with .NET API as a backend. The app contains a number forms collecting data from the user, then recalculating the result after each change and displaying the results on the screen. This has to happen without clicking the save button. At the moment the data is one large object which is sent to the API after each field change and once the save is completed it runs 3 requests to get the new calculations. I'm trying to optimize it and improve performance and I was wondering if there is any standard/best practice for this kind of systems?

Update bundle cover when new timeline item added

I have an Android-based app and I'm developing a Glass app as a companion.
Code for the app lives in two places:
Web app (OAuth authentication/token creation, creating the subscription, handling the notify callbacks from Google server)
Android app (creating sharing contact, delete sharing contact and create bundle cover for a "photo album")
After handling all of the OAuth authentication and communicating with the Mirror API, the user has the ability in the Android app to creating a sharing contact. Part of that process includes the creation of a timeline item that serves as the bundle cover for a photo album.
On Glass, as the user shares photos with that contact, the notify handler in my web app assigns the photos to the bundle created when the sharing contact was established.
All of this works fine - no problems there.
What I'm running into is that after 7 days, the timeline cards begin to fall from the Glass interface. This includes my bundle cover for the "photo album".
Obviously I need to update the bundle cover to remain active, but I'm not quite sure how to do that (without quickly ripping through my quota, that is). Using the Mirror API, I've been able to retrieve the items from the timeline, then check each one for my bundle cover (based on bundle ID and isBundleCover flag) - but that is horribly inefficient when it comes to preserving my 1000 requests per day. Am I simply using the bundle in a way that it was not intended for?
Is there an easier, more effective way of fetching the bundle cover and simply updating it so it doesn't fall off the timeline after 7 days? In a way, it seems like I shouldn't need to update the bundle every time a new photo is shared, but I'm not sure about an alternative.
As I mentioned, the bundle is created in the Android app and that ID is submitted to the backend database shared by both the web app and the Android app. Short of querying that db using the bundleID to get the original ItemID for the bundle, I'm not sure how to make the bundle ItemID accessible in the notify handler.
Thank you for any suggestions!
As you mentioned the most efficient method when it comes to preserving API quota would be to save the itemID of your bundle cover in your own datastore and retrieve it from there when needed
Apart from that there are some things you can do to make finding the card in the timeline via the Mirror API easier, since the timeline.list method offers some additional parameters to narrow down the results.
?bundleId=yourBundleId
This will only return results with the provided bundleId, depending on how many cards are in your bundle, you might find the necessary card on the first result page, so that would only need one API request
&sourceItemId=something
If your bundles are getting rather large so that the bundle cover won't be found on the first result page, one thing you can do is to additionally define a sourceItemId which you only set for the bundle cover and none of the other cards inside of the bundle. That way looking for bundleId + sourceItemId (which you can also set to the same bundleId to make it easier) will only have one item, the bundle cover, in the result.
Using those methods you should be able to find the correct card in one request and update it in a second request.

Resources