Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

flutter local storage project using several trending packages so we can have a clear understanding of which is the best choice for us

NotificationsYou must be signed in to change notification settings

MohanedZekry/flutter-local-storage-clean-architecture

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.

Table of Contents

Setup

Modules

ModulesProgress
Data
Domain
Presentation

Implementation

Hive

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.boxYou 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;}

Sembast

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp