Flutter SQLite example – CRUD Operations with ListView & sqflite plugin

In previous post, we knew how to make SQLite CRUD Operations using sqflite plugin. In this tutorial, we’re gonna build a Flutter App that allows us to make CRUD interactions with SQLite in a ListView.

Related Post:
Flutter ListView example with ListView.builder
Flutter Navigator example – Send/Return data to/from new Screen
Flutter SQLite example – CRUD operations with sqflite plugin

Firebase: Flutter Firestore example – Firebase Firestore CRUD with ListView

Example Overview

Goal

Our Flutter App will retrieve list of Notes from SQLite Database and show it in ListView widget. Then we can click on Add button to create new Note, click on a Note item to update that Note, or delete a Note with remove Button.

flutter-sqlite-example-listview-sqflite-overview

Project Structure

flutter-sqlite-example-listview-sqflite-structure

Note class (note.dart) is a Data Model.
DatabaseHelper class (database_helper.dart) handles CRUD Operations with SQLite using sqflite plugin.
ListViewNote (listview_note.dart) is a StatefulWidget with List<Note> is state variable. It shows the list using ListView.builder, sends/gets data to/from NoteScreen using Navigator.
NoteScreen (note_screen.dart) is the user interface for adding/updating Note.
– We add sqflite dependency in pubspec.yaml.

For more detailsa about ListView and Navigator, please visit:
Flutter ListView example with ListView.builder
Flutter Navigator example – Send/Return data to/from new Screen

Practice

Import sqflite

Add sqflite plugin to the dependencies section of our pubspec.yaml:

Create Data Model

lib/model/note.dart

Create Database Helper Class

lib/util/database_helper.dart

Create UI Widgets

lib/ui/listview_note.dart

lib/ui/note_screen.dart

Main App

lib/main.dart

Source Code

sqlite_listview_example

By grokonez | July 21, 2018.



Related Posts


2 thoughts on “Flutter SQLite example – CRUD Operations with ListView & sqflite plugin”

Got Something To Say:

Your email address will not be published. Required fields are marked *

*