搜索插件、代码仓与 APP 分类

插件详情v1.4.0

localstore

基于 JSON 文件的存储包为简单的 NoSQL 数据库提供持久化存储库。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
4020
喜欢数
194
Pub 分数
140

安装插件

flutter pub add localstore

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

LocalStore 是一个 Flutter/Dart 包,提供基于文件的持久化 JSON 存储,可作为简单的 NoSQL 数据库使用。它使应用程序能够在多个平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上本地存储和检索结构化数据。专为轻量级用例设计,它将数据存储在单个 JSON 文件中,无需复杂设置即可轻松管理和访问。非常适合保存用户偏好设置、缓存数据或需要在应用会话之间持久化的较小数据集。

适合场景

  • 存储用户偏好
  • 缓存 API 响应
  • 保存应用状态
  • 管理本地配置
  • 持久化小数据集

主要特点

  • 基于文件的 JSON 存储
  • 跨平台支持
  • 简单的键值接口
  • 自动序列化/反序列化
  • 轻便且快速

适合对象

  • 简单数据持久化
  • 离线优先的应用程序
  • Prototyping
  • 小型应用
  • 开发者便利

使用建议

  • 不适用于大型数据集
  • 无内置查询功能
  • 限制为 JSON 格式
  • 需要手动备份
  • 大型文件可能导致性能下降

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Localstore

pub package

Between SQL or NoSQL, there's no one best database, there's the right database for your specific project. Localstore is a JSON file-based storage package (localstorage) provides a persistent repository for simple NoSQL database.

Localstore (NoSQL) SQLite (SQL)
Data format File path (collection) Table
Data item JSON Document (doc) Record / Row
Scalability Horizontal Limited vertical
Organization Schema-less Fixed schema

Demo Screenshot

UML diagram

Localstore UML diagram

Getting Started

  1. Calling WidgetsFlutterBinding.ensureInitialized(); in main() before calling runApp():
void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}
  1. Import import 'package:localstore/localstore.dart';
import 'package:flutter/material.dart';
import 'package:localstore/localstore.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(MyApp());
}
  1. Creates an instance using the default Localstore
final db = Localstore.instance;

or using anywhere in your project.

  1. Creates new item
// gets new id
final id = db.collection('todos').doc().id;

// save the item
db.collection('todos').doc(id).set({
  'title': 'Todo title',
  'done': false
});
  1. Gets item by id
final data = await db.collection('todos').doc(id).get();
  1. Delete item by id
db.collection('todos').doc(id).delete();
  1. Fetch the documents for the collection
final items = await db.collection('todos').get();
  1. Using stream
final stream = db.collection('todos').stream;

Features and bugs

Please file feature requests and bugs at the issue tracker.

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。