NoSQL Database Storage | Flutter ObjectBox (vs Sqlite, Sqflite, Hive)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
object box is a fast efficient and easy to use nosql database that works locally on a single device or you can run it as a server to synchronize data between multiple devices in no time compared to other common databases object box is faster in all four crude operations if you look at the syntax it looks similar to the hyphnosql database whereas additionally to hive object box also supports complex crease and relationships between objects similar to the sql database let's now build our app we create a list of users inside of a list view we display these users as different list tiles and now you only need to annotate all your model objects that you want to store inside the database also every class must have an id field that you also initialize to make this work you also need to go to your pubspec yammer file and under your dependencies you need to add the object box package and under your dev dependencies you need to add the build runner and object box generator also you need to go to the build gradle file for your android setup and then go to android default config and here you set the min sdk version to at least 21. to set it up on ios go to your pod file uncommence this line and set the ios version to at least 11. and lastly you only need to go to the terminal and inside your flutter project folder you execute the command build runner build and with this out of all annotated model classes it has generated these those object box files inside the lib folder that are used in the next step by the database therefore before you run your flutter app you also need to initialize this database we create an object box class and inside of it we open the store and the store we save then inside of the class field and now we can use this store to store our users inside for this we create a new box of users that we also initialize and lastly we use this user box therefore we create three methods to get first of all a user by an id we insert a user and also delete a user also we want to read all the users from our database therefore we query all the users and we converted then to a stream object and inside the watch method we set a trigger flag to get immediately the data without waiting for the first update and finally we only need to use these get users method insert user method and delete user method inside our flutter app to access these methods we use the object box inside our main file and then we replace our current users by loading the users from our object box and finally we want to display this stream therefore we go to our list view and we wrap our list view into a stream builder where we display then this stream of users let's also create a floating action button and if we press on it then we create a new user with some fake data using the faker package and importantly this new user we need to insert then to our object box database and now before we try it out i want to point out that object box comes with two different packages if you use the first package then our app is working and it saves the users to the local database on the other hand the second package comes with the sync feature of syncing data between the server and multiple devices and for this we also need to connect our app to a server before our app is working therefore with the second package we go to our object box class and inside the init state method we also create a connection to a server as of now the server address is not existing however with this additional code we can also use now the local database inside of our app and finally we want to synchronize data between multiple devices using a server for creating the server you need to go to the object box sync website and click on get a free data sync try now then fill in your information and click on start syncing with this you should get after some time via email this object box sync server file next inside the terminal go to the location of the sync server file and then load it using docker with this this file should appear inside docker under your images next you can go to the object box sync documentation and under docker distribution you can scroll a bit down and then you can copy here this command then go to a terminal and make sure that you have navigated to the root folder of your flutter project and you paste this command inside we need to change this comment a bit so that it is pointing to the right json file inside of our flutter project lip folder and if you run this command on a windows machine then you might change the user id to 0 in case you face any errors while running this command alright let's run this command and with this it should start the object boxing server and inside the init method we want to connect to this new server that is running on localhost and for the android platform you have a different ip address also add this line so that we can later see in the console if you have successfully connected to the server and now you could run your app on multiple devices and you see it is synchronizing the data correctly over the server and finally let's go to the list star that displays our user and here we add a trailing icon to also delete a user and if we tap on an icon then we modify the data and here it is again important to put it into the object box so that the update is successful and with this we can now also delete data from our database and if you tap on an item then you can also update the user data additionally you have an admin panel where you can see all the data that is stored on the server and finally notice if you run your app on a physical device and connect to this localhost server on your computer then it is not connecting therefore make sure that you change the localhost address to the ip address of your computer while starting the server and the app should then also connect to the same ip address of your server and with this the app on our physical device is also connecting correctly to our server [Music] you
Info
Channel: HeyFlutter․com
Views: 21,651
Rating: undefined out of 5
Keywords: android, dart objectbox, flutter, flutter database, flutter database tutorial, flutter hive, flutter local database, flutter local db, flutter nosql, flutter objectbox, flutter persistent data, flutter sqflite, flutter sql, flutter tutorial, hive, ios, mobile, moor, nosql, nosql database, objectbox, programming, server, sqflite, sql database, sync, sync server
Id: BBlr8F8m9lo
Channel Id: undefined
Length: 6min 37sec (397 seconds)
Published: Mon Jun 20 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.