Complete SQLite CRUD Operations in Flutter

Complete SQLite CRUD Operations in Flutter

Now a days almost all application have to have some kind of data storage. Application without collaboration with other users will make use of local storage db – SQLite. In this tutorial, we are going to cover all CRUD operations in Flutter with SQLite.

Introduction

Now a days almost all application have to have some kind of data storage. Application without collaboration with other users will make use of local storage db – SQLite. In this tutorial, we are going to cover all CRUD operations in Flutter with SQLite.

The design part of the project already covered in previous tutorial – Design Flutter Form and ListView Widget for CRUD Operation. It includes form design and list of records inserted from the form, where we saved list of records in widget state object. So in this tutorial we can focus on SQLite CRUD Operations and finally we update existing events with SQLite CRUD Operation. Application from previous tutorial looks like this.

Flutter Form Design with TextField and Submit button

list of records in flutter ListView widget

Let’s get Started

First of all, let’s add dependencies for this project, for that update  pubspec.yamlfile as follows.

Copy to Clipboard

dependencies:
  flutter:
    sdk: flutter
  sqflite: any
  path_provider: any

Additionally here we’ve two packages-  sqflite and  path_provider.  sqflite helps to work with SQLite database. To find commonly used locations on file system, we use  path_provider package.

Caution: When it comes to yaml files, indentation is very important. Before the package name we need 2 spaces and before version name there should be a space. Instead of exact version we use  ‘any’, so latest version will be used.

Now let’s update  contact model –  models/contact.dart.

Copy to Clipboard

class Contact {

  static const tblContact = 'contacts';
  static const colId = 'id';
  static const colName = 'name';
  static const colMobile = 'mobile';

  Contact({this.id,this.name,this.mobile});
​
  int id;
  String name;
  String mobile;
​
  Contact.fromMap(Map<String, dynamic> map) {
    id = map[colId];
    name = map[colName];
    mobile = map[colMobile];
  }
​
  Map<String, dynamic> toMap() {
    var map = <String, dynamic>{colName: name, colMobile: mobile};
    if (id != null) {
      map[colId] = id;
    }
    return map;
  }
}

First of all, you could see few string constance with table name and column names. In this application, we are dealing with contact information including full-name and mobile number. Other than from a normal constructor, we have a named constructor  fromMapfor initializing an instance from a given map object. And with  toMap()function, we will convert contact object to corresponding map object.

flutter flutter article flutter database crud operations flutter sqflite tutorial flutter sqlite crud flutter sqlite example flutter sqlite orm local storage in flutter sqlite crud operations in flutter sqlite insert update delete and retrieve in flutter

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Google's Flutter 1.20 stable announced with new features - Navoki

Google has announced new flutter 1.20 stable with many improvements, and features, enabling flutter for Desktop and Web

Flutter Tutorial - Cloud Firestore🔥 | Flutter Firestore CRUD | Flutter Firestore Tutorial

#Flutter #Firebase #Google #FlutterUI #Firestore The Growing Developer Website is out !! http://thegrowingdeveloper.org Welcome back to yet another #Firebase...

SQLite/SQFlite CRUD Database Operations in Flutter

SQLite/SQFlite CRUD Database Operations in Flutter

View SQLite DB in Flutter Application

In this small article, I’ll show you how you can see the data in SQLite DB of your flutter application. In the previous two articles, we’ve covered SQLite CRUD Operation in Flutter App.

Python SQLite Database Tutorial | SQLite CRUD Operation in Python

In this Python SQLite Database Tutorial we are going to learn about working with SQLite in Python. we will learn about SQLite CRUD Operation in Python. Python SQLite Database Tutorial | SQLite CRUD Operation in Python