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

套件詳情v2.1.1

properties

一個簡單的程式庫,用於在 Dart 中管理屬性檔案(以及更多功能)

AndroidiOSmacOSWindowsLinux
近 30 天下載
92.4萬
喜歡數
9
Pub 分數
140

安裝套件

flutter pub add properties

套件介紹

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

properties 套件是一個輕量級的 Dart 庫,專為管理屬性檔案而設計,常見於設定與地區化。它支援讀取、寫入及解析標準 .properties 格式的鍵值對,並提供處理註解與編碼的額外工具。此套件與平台無關,可在 Android、iOS、macOS、Windows 與 Linux 上順暢運作。非常適合需要簡單、結構化設定儲存且無需外部相依性的應用程式。

適用情境

  • 從 .properties 檔案載入應用程式設定
  • 管理本地化字串
  • 儲存環境特定的設定
  • 解析和寫入配置數據
  • 處理純文字格式的鍵值對

主要特色

  • 支援標準的 .properties 檔案格式
  • 讀取和寫入帶註釋的鍵值對
  • 跨平台相容性
  • 用於常見操作的簡單 API
  • 處理 UTF-8 編碼與換行符

適合對象

  • 需要設定檔的小型到中型應用
  • 本地化工作流程
  • 基於環境的設定
  • Dart 專案於多個平台
  • 偏好最小依賴的開發者

使用建議

  • 不適用於複雜的嵌套設定
  • 僅限平面的鍵值結構
  • 無內建驗證或模式支援
  • 最適合簡單的使用情境,而非大規模資料管理

原始 README

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

Properties

Properties is a simple library to manage properties files (and something more) in Dart.

The project aim is to provide a simple and lightweight implementation of properties file management for Dart adding some useful but not so common features. Code and usage are very straightforward, just have a look at the Getting Started section below.

To know something more about the released version have a look at the CHANGELOG to find the version that works best for you.

Getting started

The best way to get immediately started is to have a look at the unit tests provided along with the source code.

Anyway you can go on reading this quick intro.

Using Properties you can:

  • create a new properties instance from file
Properties p = Properties.fromFile(filepath);
  • get a property out of it
String value = p.get('test.key.1');

..optionally providing a default value..

String defval = p.get('test.key.X', defval:'value X');

..or a default key..

String defkey = p.get('test.key.X', defkey:'test.key.1');
  • get an int, a double or a bool value
int anInt = p.getInt('test.key.integer');
double aDouble = p.getDouble('test.key.double');
bool aBool = p.getBool('test.key.bool');
  • get a list
List<String> list = p.getList('test.key.listofvalues');
  • add a brand new property, choosing whether to overwrite an existing entry or not
bool added = p.add('test.key.3', 'value 3', true);

and then listen to "property added" or "property updated" events

p.onAdd.listen((AddEvent e) {
        eventType = e.type;
        key = e.key;
        value = e.value;
});
  • export the content as a JSON sting, optionally choosing to export key having a given prefix and/or suffix
String jsonexport = p.toJSON([prefix, suffix]);
  • filter and extract property entries that matches custom conditions
Map<String,String> filtered = p.every((s) => s.startsWith('test'));

Running Tests

To run the tests just run the test/properties_test.dart file.

Some Limits

Output on file is not supported (yet!).

所屬分類

依賴

依賴清單 1 項

原始碼儲存庫

使用此套件的專案