- Notifications
You must be signed in to change notification settings - Fork0
MohanedZekry/flutter-local-storage-clean-architecture
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
In this project we will use trending local storage packages we will determine how long it takes each option below to perform the operations, so we can have a clear understanding of which is the best choice for us.The project is implementing a clean architecture & bloc for state management so that it’s easy to understand and easy to change as the project grows in the future and implement new technologies or packages.
Modules | Progress |
---|---|
Data | ✅ |
Domain | ✅ |
Presentation | ✅ |
is a lightweight and blazing fast key-value database written in pure Dart.Hive having the idea ofboxes
(which store data).
Hive stores its data in boxes containing key-value setsHive.box
You can call
Hive.openBox(‘name’)
regardless of whether you as of now have the box opened elsewhere.
Let’s implement the model class
import'package:hive/hive.dart';part'tasks.g.dart';@HiveType(typeId:0)classTasks{@HiveField(0)finalString name;@HiveField(1)finalString content;@HiveField(2)finalbool isDone;Tasks({requiredthis.name,requiredthis.content,requiredthis.isDone });}
Then run a code generator by typing the following command in the terminal which will automatically generate database and Adapters for us.
$flutterpackagespubrunbuild_runnerbuild
Note: Dart File name istasks.dart
so i will add parttasks.g.dart
. g stands for generated. Thus new generated file would betasks.g.dart
// GENERATED CODE - DO NOT MODIFY BY HANDpart of'tasks.dart';// **************************************************************************// TypeAdapterGenerator// **************************************************************************classTasksAdapterextendsTypeAdapter<Tasks> {@overridefinalint typeId=0;@overrideTasksread(BinaryReader reader) {final numOfFields= reader.readByte();final fields=<int,dynamic>{for (int i=0; i< numOfFields; i++) reader.readByte(): reader.read(), };returnTasks( name: fields[0]asString, content: fields[1]asString, isDone: fields[2]asbool, ); }@overridevoidwrite(BinaryWriter writer,Tasks obj) { writer ..writeByte(3) ..writeByte(0) ..write(obj.name) ..writeByte(1) ..write(obj.content) ..writeByte(2) ..write(obj.isDone); }@overrideintget hashCode=> typeId.hashCode;@overridebooloperator==(Object other)=>identical(this, other)|| otherisTasksAdapter&& runtimeType== other.runtimeType&& typeId== other.typeId;}
is database stands for Simple Embedded Application Store databaseNoSQL persistent store database solution for single process io applications.
final _kDbFileName='sembast_tasks.db';final _kTasksStore='tasks_store';lateDatabase _database;StoreRef<int,Map<String,dynamic>> _tasksStore;appDocumentDir=awaitgetApplicationDocumentsDirectory();dbPath=join(appDocumentDir.path, _kDbFileName);_database=await databaseFactoryIo.openDatabase(dbPath);_tasksStore= intMapStoreFactory.store(_kTasksStore);
About
flutter local storage project using several trending packages so we can have a clear understanding of which is the best choice for us
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.