Floor provides a neat SQLite abstraction for your Flutter applications inspired by the Room persistence library. It comes with automatic mapping between in-memory objects and database rows while still offering full control of the database with the use of SQL

Image for post

Floor Database

You can save, query and, delete your Objects in a simple and a direct way with Floor database!

Start

To start with Floor, let’s add these dependencies to pubspec.yaml

dependencies:
   flutter:
     sdk: flutter
   floor: ^0.14.0

 dev_dependencies:
   floor_generator: ^0.14.0
   build_runner: ^1.7.3

Entity classes

The entity class will represent a database table Columns. Tthe @entity marks the class as a persistent class and you need to add a primaryKey

// entity/student.dart

 import 'package:floor/floor.dart';

 @Entity(tableName: 'students')
 class Student {
   @primaryKey(autoGenerate: true) 
   final int id;

   final String name;
   final Float grade;
   Person(this.id, this.name, this.grade);
 }

#flutter #flutter-database #room-database #dart

Room Database Equivalent for Flutter
34.45 GEEK