_descriptionController.text = existingJournal _journals.firstWhere((element) => element = id) It will also be triggered when you want to update an item This function will be triggered when the floating button is pressed _refreshJournals() // Loading the diary when the app startsįinal TextEditingController _titleController = TextEditingController() įinal TextEditingController _descriptionController = TextEditingController() This function is used to fetch all data from the database Static Future createTables(sql.Database database) async ) : super(key: createState() => _HomePageState() Import 'package:sqflite/sqflite.dart' as sql Full code in sql_helper.dart: import 'package:flutter/foundation.dart'
SQLITE DATABASE EDITOR INSTALL
Install the sqflite plugin (note that the name has an “f”): flutter pub add sqfliteĢ. In the lib folder, add a new file named sql_helper.dart. It will be automatically added by SQLiteġ. Below is the structure of the table: Column We are going to create an SQLite database called kindacode.db. There are an update button and a delete button associated with each “item”.Ī demo is worth than a thousand words: Advertisements Database Structure The saved “items” are fetched from the SQLite database and displayed with a list view. These text fields are used to create a new “item” or update an existing “item”. That bottom sheet contains 2 text fields corresponding to “title” and “description”. The app has a floating button that can be used to show a bottom sheet. In the scope of this tutorial, “activity”, “item” and “journal” are interchangeable. For simplicity’s sake, we will call each of these activities a “journal” or an “item”.
The app we are going to make is an offline diary that lets users record the activities they did during the day. A computer with Flutter installed, a code editor (VS Code is great).
If you don’t, please see the official docs first. In order to fully understand the example, you should have: Advertisements