How to create flutter app's offline and online - mongodb

i am just looking for ideas about how to make the app work in online and offline modes(it is a todo app and it should work online and offline both)
I have a todo app that stores the data in sqflite database(locally on the phone) when the app goes online I want the data to be synced with my online database for online database i am using from mongodb. i am just looking for suggestions and also i want to ask which offline database is fine beside of mongode, Hive or sqflite.

you can use a shared_prefernce library and create a function if phone not connected to wifi return null else if connected use socket emit and clear local storage

MongoDB's Realm supports the sync feature, however this would lock your application to the MongoDB's Atlas hosted Database.

Related

Which alternative to "Firebase Storage" could I use for my Flutter App?

I'm developing an app with Flutter and I need a lot of database storage to store my data (images and videos).
Currently I'm using Firebase for:
"User Authentication, Firestore Database, Dynamic Links, Storage and so on"
The pricing for the storage (GB stored) itself is ok for me but Firebase also charges for GB Transfered and Operations(uploads & downloads) which can get expensive as you can see in the snapshot below:
I am actually looking for an alternative to Firebase Storage which does not charge for Data transfer of Operations (at least sth. which is not that expensive).
Does anyone know which cloud storage I could use instead and also how to migrate in my flutter app?
I'm also open to use a own server running on a VPS but I have no clue how I would establish a connection to the own server in order to be able to up- and download media files.
Please provide a tutorial/instructions how to build your own server and connect with flutter app since I'm interested on anyway.
I would recommend using Supabase, it's a Firebase alternative and it's open source, supports Flutter/Dart and supports the storage service.
Check it from here Supabase storage
you could configure it and use it with your own hosting, and it will cost you only the price of hosting it on some cloud service, where you will store your files.

Change The status of user to offline in firestore

I have Taxi App, And I need add when the driver closed the app, the status of the driver changed to offline in firestore
how I can do that?
plz explain for me
Firestore has no built-in capability to write something in the database after the client has disconnected.There's a solution but that uses the Firebase Realtime Database and Cloud Functions to store presence information in Firestore too, which is documented here Build presence in Cloud Firestore.Found this blog you can also check this which might help.
Depending on the type of app you're building, you might find it useful
to detect which of your users or devices are actively online —
otherwise known as detecting "presence."
Cloud Firestore doesn't natively support presence, but you can
leverage other Firebase products to build a presence system.
You can refer this stackoverflow thread1 & thread2

Need some clarification about Mongo Realm and Mongo Atlas. And App user data

I am new to app development and I've been looking into using MongoDB Atlas and MongoDB Realm. A few questions I couldn't find answers from their documentation, hopefully someone can clarify for me.
Is it correct to think Mongo Realm is client DB and it uses sync to the MongoDB Atlas, so if I make a React Native app using Realm, then user store/retrieve data from one device, and can pick up from another device (if they logged in with the same account)?
If point 1 is yes, then if I want to make a web app as well and skip Realm and only use Mongo Atlas, can I use the data synced from Realm? E.g. a task list created with my React Native app in Realm and synced to Atlas, can I create a web app and query synced data stored in Atlas direct say with Mongoose?
If point 2 is true, how can I access app user from Atlas, it seems it only exists only in Realm, what's approach here?
Final point is, for this kind of cross platform app, what's the best approach?
Many thanks,
I am currently working on implementing an app with the setup you describe.
Is it correct to think Mongo Realm is client DB and it uses sync to the MongoDB Atlas, so if I make a React Native app using Realm, then user store/retrieve data from one device, and can pick up from another device (if they logged in with the same account)?
Yes! You can try this easily with the Task Tracker App by MongoDB Realm Sync
if I want to make a web app as well and skip Realm and only use Mongo Atlas, can I use the data synced from Realm? E.g. a task list created with my React Native app in Realm and synced to Atlas, can I create a web app and query synced data stored in Atlas direct say with Mongoose?
Yes! - Realm Sync does not support React Native Web as far as I know, therefore creating a Web App with React or Next.js is a good alternative as MongoDB Atlas data synced from mobile devices via Realm Sync can be easily be accessed in this way. I am currently looking at the following approach: How to Integrate MongoDB Into Your Next.js App
how can I access app user from Atlas, it seems it only exists only in Realm, what's approach here?
Try the above mentioned example app with a few users and this will become more clear to you. In this case the MongoDB Atlas database will be 'partitioned' by userID making it easy to get just the data you want for the web app. Look into Partition Atlas Data into Realms to understand this more fully.
for this kind of cross platform app, what's the best approach?
Well what is the best approach is difficult to answer as the question is too broad, and it depends a lot on what the app is for and how it is used.
Personally I have good reasons for choosing Realm Sync, as I require offline-first capability. I am building a React Native iOS/Android app with many users having their own data. Therefore I am 'partitioning' by userID. My main use case is mobile and the web app is merely intended to support easy data entry and editing on a laptop or desktop. Therefore not all features of the mobile app need to be replicated in the web app. This is just my personal approach.

Can I pre-cache data to work offline in mobile app using AppSync?

I am developing an Android and iOS app that could be used in areas that have a very poor or no data connection. It is a requirement for the app to be pre-loaded with all of the data so it will work even if the app never communicated with the server, but it also needs to be able to update and sync when a connection is made. Is it possible to manually populate the AppSync (Apollo) cache database with data on launch and query and mutate it later? The app also contains several search and filter queries. Our backend API is currently using GraphQL.
I have seen this question, Is it possible to build offline-first mobile apps using AWS AppSync?, but it is a little different that what I'm asking.
The recommendation would be to hydrate (read: pre-load with data) a local SQLite database after install. SQLite is what the 'local cache' uses to persist data on the device.
Refer to this github issue for a code example of how to do this:
https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/160

Firestone offline capabilities flutter

I know that Firestone will store data if the user is offline and I saw that there is a way to do this with native code, but is it possible to enable these offline capabilities in flutter itself?
Firebase firestore support full offline. I’m using it myself. So long as you’ve read the data at least once before going offline. If using firebase authentication - the custom option also works offline. Google sign-in does not.
The downside to firebases offline capabilities is that it’s only firestore (not counting the older firebase db) and not the other products like cloud storage.
So for example I’ve written an app and the document side of it is fully offline enabled however you can take photos in the app and I had the write the offline capabilities to sync this photos with firebase cloud storage myself.
(I basically just keep them in a pending folder and try to sync them when the device has connectivity.)