搜索分类、插件与代码仓

cr_json_widget 封面
插件详情v1.1.1

cr_json_widget

一个可视化树结构的小部件,其中节点可以是任何小部件。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
1340
喜欢数
21
Pub 分数
150

安装插件

flutter pub add cr_json_widget

插件介绍

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

cr_json_widget 是一个 Flutter 包,用于显示分层树状结构,其中每个节点可以是任何自定义小部件。它使开发者能够以交互式和可定制的方式可视化 JSON 数据或嵌套结构。该小部件支持节点的动态展开和折叠,非常适合用于调试、配置视图或数据探索界面。专为跨平台使用而设计,可在 Android、iOS、Web、macOS、Windows 和 Linux 上无缝运行。其灵活的架构允许与各种数据源和 UI 组件集成。

适合场景

  • 可视化嵌套的 JSON 数据
  • 调试复杂数据结构
  • 交互式配置面板
  • 数据探索界面
  • 自定义树状UI

主要特点

  • 支持任何 widget 作为节点
  • 动态可展开/可折叠节点
  • 跨平台兼容性
  • 可自定义的树状样式
  • 与 JSON 数据的轻松集成
  • 可扩展以进行自定义渲染

适合对象

  • 开发调试工具的开发者
  • UI设计师创建数据可视化
  • 需要分层数据展示的应用程序
  • 正在从事多平台项目的团队
  • 涉及嵌套配置数据的项目

使用建议

  • 可能会影响非常大的树状结构的性能
  • 需要谨慎的状态管理以实现动态更新
  • 自定义节点小部件必须处理布局约束
  • 有限的内置编辑功能
  • 最适合只读或简单交互场景

原始 README

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

cr_json_widget

This widget visualises a tree structure, where a node can be any widget.

Examples

Getting Started

  1. Add plugin to your project:
    dependencies:
        cr_json_widget: ^1.1.0
    

Usage

CrJsonWidget
This widget display all children as simple ListView and that it does not have good performance with huge jsons.
  1. Create JsonController:

    final _jsonController = JsonController(
        allNodesExpanded: false,
        uncovered: 3,
    );
    

    allNodesExpanded - Sets whether the json tree is expanded by default

    uncovered - Sets the value to what nesting by default the json tree will be expanded

  2. Add widget: 2.1 Accepts json as Map <String, Any> and builds the tree automatically:

        ...
        final data = <String, dynamic>{
            'integer': 1, 
            'string': 'test', 
        }
        ...
        CrJsonWidget(
            ..
            json: data
        )
        ...
    

    2.2 Accepts your custom List , for placement in the form of a tree:

        CrJsonWidget(
            ..
        jsonNodes: [
            JsonNode(
                content: const Text(
                    'root1',
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Colors.red,
                    ),
                ),
            ),
            JsonNode(
                content: const Text(
                    'root2',
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Colors.deepPurpleAccent,
                    ),
                ),
                children: [
                    JsonNode(
                        content: const Text('child21'),
                    ),
                    JsonNode(
                        content: const Text('child22'),
                    ),
                    JsonNode(
                        content: const Text('root23'),
                        children: [
                            JsonNode(
                                content: const Text('child231'),
                            ),
                        ],
                        ),
                    ],
                ),
            ],
        ),
    

Full implementation example:

    ...
    CrJsonWidget(
        iconOpened: Icon(
            Icons.arrow_drop_down,
            size: _iconSize,
        ),
        iconClosed: Icon(
            Icons.arrow_right,
            size: _iconSize,
        ),
        indentHeight: 5,
        indentLeftEndJsonNode: _iconSize,
        jsonNodes: [
            JsonNode(
                content: const Text(
                    'root1',
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Colors.red,
                    ),
                ),
            ),
            JsonNode(
                content: const Text(
                    'root2',
                    style: TextStyle(
                        fontWeight: FontWeight.bold,
                        color: Colors.deepPurpleAccent,
                    ),
                ),
                children: [
                    JsonNode(
                        content: const Text('child21'),
                    ),
                    JsonNode(
                        content: const Text('child22'),
                    ),
                    JsonNode(
                        content: const Text('root23'),
                        children: [
                            JsonNode(
                                content: const Text('child231'),
                            ),
                        ],
                        ),
                    ],
                ),
            ],
        jsonController: _jsonController,
    ),

iconOpened - Custom icon for opening a node

iconClosed - Custom icon for closing a node

indentHeight - Vertical indent between levels

indentWidth - Horizontal indent between levels

indentLeftEndJsonNode - The starting position of the ending node (Recommended size is the size of the icon)

json - Parsed json

jsonNodes - List of root level json nodes

jsonController - Json controller to manage the json state

Json Recycler Widgets
Use these widgets, if you have huge jsons. Since these widgets have builders, huge jsons don't affect its performance in any way.
  1. Create JsonRecyclerController:
      final _jsonController = JsonRecyclerController(
      saveClosedHistory: false,
      showStandardJson: false,
      isExpanded: true,
    );

isExpanded - Sets whether the json tree is expanded by default

saveClosedHistory - The parameter defines whether the previously opened child tabs should be saved or not

showStandardJson - Will show json with curly braces

jsonKeyColor - Json key color in the tree

intColor - Set color of int parameters in the tree of json

doubleColor - Set color of double parameters in the tree of json

stringColor- Set color of string parameters in the tree of json

nullColor- Set color of null parameters in the tree of json

boolColor - Set color of bool parameters in the tree of json

objectColor - Set color of object parameters in the tree of json

standardJsonBackgroundColor - Set background color of widget

iconOpened - Custom icon for opening a node

iconClosed - Custom icon for closing a node

fontStyle - Set font style of text. By default, the inherited style used

fontWeight - Set font weight of text. By default FontWeight.bold

horizontalSpaceMultiplier- The distance by which the left child element will be offset from the parent

verticalOffset - The space by which the child element will be offset from the parent

additionalIndentChildElements - Additional indentation for aligning child elements depending on the size of the parent icon

  1. Add widget:

❗ Since the CrJsonRecyclerWidget has a builder in it, you must set the height or you will get an error

2.1 CrJsonRecyclerWidget:

     ...
     final data = <String, dynamic>{
         'integer': 1, 
         'string': 'test', 
     }
     ...
    CrJsonRecyclerWidget(
          ..
           json: data,
         ),
     ...

json - Parsed json

jsonController - Json controller to manage the json state

rootExpanded - Whether to expand the root nesting by default

Full implementation example:

      ...
      Expanded(
          child: CrJsonRecyclerWidget(
            json: json,
            jsonController: _jsonController,
            rootExpanded: true,
          ),
        ),
      ...

2.2 CrJsonRecyclerSliver:

     ...
     final data = <String, dynamic>{
         'integer': 1, 
         'string': 'test', 
     }
     ...
           CrJsonRecyclerSliver(
              ...
               json: json,
           ),
    ...

json - Parsed json

jsonController - Json controller to manage the json state

rootExpanded - Whether to expand the root nesting by default

Full implementation example:

        ...
        CustomScrollView(
              slivers: [
                    CrJsonRecyclerSliver(
                          jsonController: _jsonController,
                          json: json,
                          rootExpanded: true,
                    ),
              ],
          ),
        ...

所属分类

源码仓库

使用此插件的项目