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

套件詳情v2.0.3

sp_util

Flutter shared_preferences 插件工具,支援取得預設值、儲存物件與物件清單。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
3960
喜歡數
58
Pub 分數
160

安裝套件

flutter pub add sp_util

套件介紹

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

sp_util 是一個 Flutter 工具包,透過提供增強功能(例如取得預設值、儲存物件和管理物件清單)來簡化 shared_preferences 的使用。它簡化了跨平台的永久資料儲存,讓處理使用者偏好設定和應用狀態變得更容易。基於 shared_preferences 插件建構,支援 Android、iOS、Web、macOS、Windows 和 Linux。此套件減少重複程式碼,提升開發者在儲存與讀取序列化資料時的生產力。

適用情境

  • 儲存使用者偏好
  • 儲存應用程式設定
  • 持久化用戶會話數據
  • 管理設定清單
  • 處理快取資料
  • 儲存序列化物件

主要特色

  • 支援預設值檢索
  • 啟用物件序列化
  • 處理物件列表持久化
  • 減少樣板程式碼
  • 跨平台相容性
  • 易於使用的 API

適合對象

  • 簡單資料持久化需求
  • 使用者偏好管理
  • 應用狀態儲存
  • 跨平台應用
  • 尋求最小化設定的開發者
  • 使用 shared_preferences 的項目

使用建議

  • 不適用於大型資料集
  • 僅限簡單資料類型
  • 需要 JSON 序列化
  • 無內建加密
  • 依賴於 shared_preferences
  • 不適合複雜的資料庫操作

原始 README

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

sp_util

Pub      Pub

Flutter shared_preferences plugin util, support get default value, save object, object list. Use SharedPreferences easily.

Pub
dependencies:
  sp_util: ^2.0.3
APIs
getObj
getObjList
putObject
getObject
putObjectList
getObjectList
getString
putString
getBool
putBool
getInt
putInt
getDouble
putDouble
getStringList
putStringList
getDynamic
haveKey
getKeys
remove
clear
reload
isInitialized
Example
/// Example One.
/// await SpUtil initialization to complete before running the app.
/// sp init time release about 30ms,debug about 100ms.(Test on Android.)
void main() async {
  await SpUtil.getInstance();
  runApp(MyApp());
}

class MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
 
     /// examples
    SpUtil.putString("username", "sky24");
    String userName = SpUtil.getString("username", defValue: "");
    print("userName: " + userName);

    /// save object example.
    /// 存储实体对象示例。
    City city = City();
    city.name = "成都市";
    SpUtil.putObject("loc_city", city);

    City hisCity = SpUtil.getObj("loc_city", (v) => City.fromJson(v));
    print("City: " + (hisCity == null ? "null" : hisCity.toString()));

    /// save object list example.
    /// 存储实体对象list示例。
    List<City> list = List();
    list.add(City(name: "成都市"));
    list.add(City(name: "北京市"));
    SpUtil.putObjectList("loc_city_list", list);

    List<City> dataList = SpUtil.getObjList("loc_city_list", (v) => City.fromJson(v));
    print("CityList: " + (dataList == null ? "null" : dataList.toString()));
  }
  @override
  Widget build(BuildContext context) {
    return MaterialApp();
  }
}  


/// Example Two.
/// add SplashPage, complete sp initialization on the SplashPage. Then you can use it synchronously to the homepage。
...
...
More Util

common_utils Dart common utils.

  1. TimelineUtil : timeline util.
  2. TimerUtil : countdown,timer.
  3. MoneyUtil : fen to yuan, format output.
  4. LogUtil : simply encapsulate print logs.
  5. DateUtil : date conversion formatted output.
  6. RegexUtil : regular verification of mobile phone numbers, ID cards, mailboxes and so on.
  7. NumUtil : keep [x] decimal places, add subtract multiply divide without loosing precision.
  8. ObjectUtil : object is empty, two List is equal.
  9. EncryptUtil : xor, md5 ,Base64..
  10. TextUtil : hide phoneNo.
  11. JsonUtil : json to object.

flustars Flutter common utils.

  1. SpUtil : SharedPreferences Util.
  2. ScreenUtil : get screen width height density, appBarHeight, statusBarHeight, orientation.
  3. WidgetUtil : get Widget width height,coordinates.
  4. ImageUtil : get image size.
  5. DirectoryUtil : Directory Util.
dependencies:
  # https://github.com/Sky24n/common_utils
  common_utils: ^1.2.1
  # https://github.com/Sky24n/flustars
  flustars: ^0.3.3
  # https://github.com/Sky24n/sp_util
  sp_util: ^2.0.0

Changelog

Please see the Changelog page to know what's recently changed.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案