搜尋套件、儲存庫與 APP 分類

套件詳情v6.0.0

localstorage

適用於 Flutter 的本機儲存空間。React Native 的 AsyncStorage 替代方案。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
1.3萬
喜歡數
382
Pub 分數
160

安裝套件

flutter pub add localstorage

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Localstorage 是一個 Flutter 套件,提供持久性鍵值儲存,作為 React Native 的 AsyncStorage 替代方案。它可在 Android、iOS、Web、macOS、Windows 與 Linux 等多個平台實現應用重啟後的資料儲存與讀取。此套件以簡單易用為設計核心,支援異步讀寫字串、數字及可序列化為 JSON 的物件。該套件抽象了平台特定的儲存機制,確保在不同環境下行為一致。適用於快取、使用者偏好設定或不需要完整資料庫的小規模資料持久化情境。

適用情境

  • 儲存使用者偏好
  • 快取 API 回應
  • 持久化應用狀態
  • 儲存表單資料
  • 管理身份驗證令牌

主要特色

  • 跨平台相容性
  • 非同步讀/寫作業
  • JSON 序列化支援
  • 簡單 API
  • 輕巧且快速

適合對象

  • 小規模數據持久化
  • 離線優先的應用程式
  • 使用者設定管理
  • Prototyping
  • 需要輕量級儲存的應用

使用建議

  • 不適用於大型資料集
  • 無內建查詢功能
  • 資料預設未加密
  • 僅限基本資料類型
  • 需要手動錯誤處理

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

LocalStorage

LocalStorage for Flutter.

[!IMPORTANT]
LocalStorage is not intended to store large amounts or sensitive data.

Installation

flutter pub add localstorage

or add dependency to pubspec.yaml manually

dependencies:
  localstorage: ^5.0.0

API docs

LocalStorage API documentation

Usage

import 'package:flutter/material.dart';
import 'package:localstorage/localstorage.dart';

late final ValueNotifier<int> notifier;

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initLocalStorage();

  notifier = ValueNotifier(int.parse(localStorage.getItem('counter') ?? '0'));
  notifier.addListener(() {
    localStorage.setItem('counter', notifier.value.toString());
  });

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: ValueListenableBuilder<int>(
            valueListenable: notifier,
            builder: (context, value, child) {
              return Text('Pressed $value times');
            },
          ),
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            notifier.value++;
          },
          child: const Icon(Icons.add),
        ),
      ),
    );
  }
}

Contributors

License

MIT

所屬分類

依賴

依賴清單 3 項

原始碼儲存庫

使用此套件的專案