Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 220.127.116.11 release ready!
Before starting our blog topic Floor In Flutter, we will discuss in short what is Floor and why we need Floor in a flutter. The floor basically a flutter dependency that supports the RoomDataBase in the flutter application. Those who have worked on Android application development can relate to the RoomDataBase. RoomDatabase basically provides the abstraction layer over the SQLite database. RoomDatabase consists of annotation which helps to perform the CRUD(CREATE, READ, UPDATE and DELETE) operation easily.
The floor is inspired by the RoomDatabase of android and has kind of same functionality and working logic as the flutter framework. It automatically mapped the object with the row of the table, while still offering full control of the database with the use of SQL. We can store the primitive and non-primitive(Custom Object) in the Floor Database.
For implementing the floor in a flutter, we will follow the mentioned steps:
I have used the following version dependency, you can use any version as per your requirement from the Flutter Dev console. And also add the dev dependency for the compilation of code.
We need to create an abstract class that has abstract methods of performing CRUD operation in the Database. I have stored the user name in the database, and fetching the list of the user name. You can use it according to your use.
I have created the class UserDetails in which I have added String type variable name, you can use multiple variables as per your need. I have used an annotation called entity with this class. An entity represents a table in the database, and every table has a primary key for fetching some specific data from the database.
Note: We can also store custom objects in the database, but for this, we need to create a converter for each custom object. Which will convert the custom objects to primitive data types and vice versa.
In this step, we will create the database for our model class (UserDetails in my case). We will create an abstract class that extends the FloorDatabase class.
Note: Don’t forget to import the ” part ‘UserDatabase.g.dart’ ” file as this consists of all the code of the Database. In my case, my “g.dart” file name is mentioned below.
–> You can generate the file after adding it with the help of the following command that you have to run on the terminal:
Now you have generated code for saving and fetching the data from the database. I have created two methods in which I am saving the UserDetails and fetching the List of the UserDetails respectively. For obtaining an instance of the database, use the generated “$FloorUserDatabase” class, which allows access to a database builder. The name is being composed by "$Floor" and the database class name.
In this way, you can save the data in the database and fetch it from it. You can use Floor Database as per your need.
I hope this blog helps you to understand the Floor In Flutter.
For more information, please go through the Flutter Dev console
Your email address will not be published. Required fields are marked*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
Excellent work, fast, good quality and understood the brief perfectly! Quick responses developing the project and very good cooperation. I suggest to anyone.
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.