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

套件詳情v3.1.0

cross_local_storage

適用於行動裝置(Android/iOS)、Web 與桌面端(Windows、macOS、Linux)的 SharedPreferences 包裝。同時也提供 JSON 檔案儲存功能。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
343
喜歡數
32
Pub 分數
160

安裝套件

flutter pub add cross_local_storage

套件介紹

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

CrossLocalStorage 是一個 Flutter/Dart 套件,為行動裝置(Android/iOS)、Web 與桌面平台(Windows、macOS、Linux)提供統一的永久儲存介面。它在行動與 Web 平台上封裝 SharedPreferences,而在桌面環境中則提供基於 JSON 檔案的儲存。此套件確保跨平台的資料存取一致性,簡化跨平台應用開發。支援鍵值儲存與結構化 JSON 檔案持久化,非常適合可靠地儲存使用者偏好、應用狀態或小型資料集。

適用情境

  • 跨平台儲存使用者偏好
  • 在多平台應用中持久化應用狀態
  • 將設定檔儲存為 JSON
  • 在網頁和桌面應用程式中管理本機資料
  • 在行動裝置和桌面裝置之間共用簡單資料
  • 啟用離線優先功能

主要特色

  • 統一 API 適用於所有平台
  • 桌面端的JSON檔案儲存
  • SharedPreferences 在移動/web 上的回退
  • 平台無關的資料存取
  • 支援字串、整數、布林值和複雜類型
  • 自動序列化/反序列化

適合對象

  • 跨平台 Flutter 開發人員
  • 需要在多個目標上進行本機持久化的應用
  • 開發人員避免使用平台特定程式碼
  • 使用 JSON 儲存本機資料的專案
  • 優先考慮程式碼重用的團隊
  • 需要輕量級本機儲存的應用

使用建議

  • 不適用於大規模數據
  • JSON 檔案儲存可能會影響桌面端的效能
  • 限於簡單資料結構
  • 無內建加密
  • 在桌面端需要仔細處理檔案路徑
  • 不適用於高頻率寫入

原始 README

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

cross_local_storage

Build Pub GitHub GitHub stars

Wraps NSUserDefaults (on iOS and macOS), SharedPreferences (on Android), LocalStorage (on Web) and JSON file (on Windows and Linux), providing a persistent store for simple data. Data is persisted to disk asynchronously. Neither platform can guarantee that writes will be persisted to disk after returning and this plugin must not be used for storing critical data.

Getting Started

In order to use this plugin, add dependency in the pubspec.yaml:

cross_local_storage: any

or

cross_local_storage:
  git:
    url: https://github.com/marchdev-tk/cross_local_storage

Add an import to dart file:

import 'package:cross_local_storage/cross_local_storage.dart';
Example
import 'package:flutter/material.dart';
import 'package:cross_local_storage/cross_local_storage.dart';

void main() {
  runApp(MaterialApp(
    home: Scaffold(
      body: Center(
      child: RaisedButton(
        onPressed: _incrementCounter,
        child: Text('Increment Counter'),
        ),
      ),
    ),
  ));
}

_incrementCounter() async {
  LocalStorageInterface prefs = await LocalStorage.getInstance();
  int counter = (prefs.getInt('counter') ?? 0) + 1;
  print('Pressed $counter times.');
  await prefs.setInt('counter', counter);

Feature requests and Bug reports

Feel free to post a feature requests or report a bug here.

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案

暫無相關資料。