搜索插件、代码仓与 APP 分类

插件详情v2.1.0

yaml_writer

一个用于编写 YAML 文档的库,支持对象编码和 'dart:convert' 的 'Converter'。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
66.6万
喜欢数
29
Pub 分数
160

安装插件

flutter pub add yaml_writer

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

yaml_writer 是一个 Dart 库,旨在生成支持对象编码并集成 'dart:convert' Converter 接口的 YAML 文档。它可无缝将 Dart 对象序列化为结构化的 YAML 格式,非常适合用于配置文件、数据交换和持久化存储。该包在所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上均兼容。专注于简洁性和互操作性,它扩展了标准 Dart 生态系统,同时保持输出清晰易读。

适合场景

  • 生成配置文件
  • 将 Dart 对象序列化为 YAML
  • YAML 格式的数据持久化
  • 与 dart:convert 的互操作性
  • 创建结构化数据导出

主要特点

  • 对象编码支持
  • 与 dart:convert Converter 的集成
  • 跨平台兼容性
  • 干净且可读的 YAML 输出
  • 用于编写 YAML 文档的简单 API

适合对象

  • 处理配置数据的开发者
  • 需要 YAML 输出的应用程序
  • 使用 dart:convert 工具的项目
  • 跨平台 Flutter 应用
  • 需要结构化文本序列化的工具

使用建议

  • 仅限编写 YAML(不支持解析)
  • 依赖外部依赖项以实现完整功能
  • 未针对大规模 YAML 生成进行优化
  • 输入对象无内置验证
  • 需要手动处理复杂的嵌套结构

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

yaml_writer

pub package Null Safety Codecov Dart CI GitHub Tag New Commits Last Commits Pull Requests Code size License

A library to write YAML documents, supporting Object encoding and dart:convert Converter.

Usage

A simple usage example:

import 'package:yaml_writer/yaml_writer.dart';

void main() {
  final yamlWriter = YamlWriter();

  final yamlDoc = yamlWriter.write({
    'name': 'Joe',
    'ids': [10, 20, 30],
    'desc': 'This is\na multiline\ntext',
    'enabled': true,
  });

  print(yamlDoc);
}

OUTPUT:

name: "Joe"
ids: 
  - 10
  - 20
  - 30
desc: |-
    This is
    a multiline
    text
enabled: true

YAML Strings

The writer will try to encode strings using the best format depending on the text, avoiding to escape " and using | for multiline texts.

Encoding Objects

You can use YAMLWriter.toEncodable to convert an Object to an encodable version, similar to what is done by dart:convert JsonEncoder.

If YAMLWriter.toEncodable is not set, it will try to call toJson().

Features and bugs

Please file feature requests and bugs at the issue tracker.

Author

Graciliano M. Passos: gmpassos@GitHub.

Liplum: liplum@GitHub

License

Dart free & open-source license.

所属分类

源码仓库

使用此插件的项目