搜索插件、代码仓与 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 项

源码仓库

使用此插件的项目