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

json_editor_flutter 封面
插件详情v1.4.2

json_editor_flutter

使用此软件包编辑您的 JSON 对象。使用此用户友好的小部件创建和删除对象。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
3560
喜欢数
31
Pub 分数
150

安装插件

flutter pub add json_editor_flutter

插件介绍

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

json_editor_flutter 是一个用户友好的 Flutter 包,可在您的应用中实现对 JSON 对象的交互式编辑。它提供了一个简洁直观的界面,用于创建、修改和删除 JSON 键和值。该控件支持实时验证和嵌套对象操作,非常适合需要在 UI 中直接处理 JSON 数据的开发者。支持所有主要平台,可无缝集成到需要动态 JSON 输入的 Flutter 应用中。

适合场景

  • 编辑配置文件
  • 调试 API 响应
  • 构建表单生成器
  • 创建 JSON 模式编辑器
  • 原型数据结构

主要特点

  • 交互式 JSON 树形视图
  • 实时验证
  • 对嵌套对象的支持
  • 跨平台兼容性
  • 与 Flutter 表单轻松集成

适合对象

  • 开发人员构建管理面板
  • 需要 JSON 输入的应用程序创建者
  • 学习JSON的教育工具
  • API 测试和调试工具

使用建议

  • 可能需要自定义样式以适应复杂布局
  • 仅限基本的 JSON 操作
  • 未针对非常大的 JSON 文件进行优化
  • 无内置的导出/导入功能

原始 README

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

JsonEditor class

Edit your JSON object with this package. Create, edit and format objects using this user friendly widget.

See the sample below for an example.

JsonEditor Live Demo

Screenshot

JsonEditor

Getting started

  • Add the package in your flutter project. Run this command in terminal flutter pub add json_editor_flutter.
  • Import the package import 'package:json_editor_flutter/json_editor_flutter.dart';.

Using JsonEditor

JSON can be edited in two ways, Tree editor or text editor. You can disable either of them.

When UI editor is active, you can disable adding/deleting keys by using enableMoreOptions. Editing keys and values can also be disabled by using enableKeyEdit and enableValueEdit.

When text editor is active, it will simply ignore enableMoreOptions, enableKeyEdit and enableValueEdit.

duration is the debounce time for onChanged function. Defaults to 500 milliseconds.

editors is the supported list of editors. First element will be used as default editor. Defaults to [Editors.tree, Editors.text].

Example

JsonEditor(
  onChanged: (value) {
    // Do something
  },
  json: jsonEncode({
    "name": "John Doe",
    "age": 24,
    "hobbies": ["Reading", "Coding"],
    "address": {
      "street": "Main Street",
      "number": 1234567890,
      "city": "New York"
    }
  }),
)

Enums

Supported editors for JSON Editor.

enum  Editors { tree, text }

Customization

expandedObjects

[expandedObjects] refers to the objects that will be expanded by default. Index can be provided when the data is a List.

data = {
  "hobbies": ["Reading books", "Playing Cricket"],
  "education": [
    {"name": "Bachelor of Engineering", "marks": 75},
    {"name": "Master of Engineering", "marks": 72},
  ],
}

For the given data

  1. To expand education pass => ["education"]
  2. To expand hobbies and education pass => ["hobbies", "education"]
  3. To expand the first element (index 0) of education list, this means we need to expand education too. In this case you need not to pass "education" separately. Just pass a list of all nested objects => [["education", 0]]
JsonEditor(
  expandedObjects: const [
    "hobbies",
    ["education", 0] // expands nested object in `education`
  ],
  onChanged: (_) {},
  json: jsonEncode(data),
)

Properties

Property Type Default Value Description
json String required JSON object to be edited
onChanged Function required Callback function that will be called with the new data
duration Duration 500 ms Debounce duration for onChanged function
enableMoreOptions bool true Enables more options like adding or deleting data
enableKeyEdit bool true Enables editing of keys
enableValueEdit bool true Enables editing of values
themeColor Color? null Theme color for the editor, changes the border color and header color
editors List [tree, text] List of supported editors, first element will be used as default editor
actions List<Widget> [] A list of Widgets to display in a row at the end of header
enableHorizontalScroll bool false Enables horizontal scroll for the tree view
searchDuration Duration 500 ms Debounce duration for search function
hideEditorsMenuButton bool false Hides the option of changing editor
expandedObjects List [] List of objects to expand by default

Additional information

You can raise an issue/feature request on github Json Editor Issues


Please leave a like if you find this package useful. :+1:

所属分类

源码仓库

使用此插件的项目

暂无相关数据。