搜尋套件、儲存庫與 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:

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。