搜尋套件、儲存庫與 APP 分類

flutter_tree_pro 封面
套件詳情v0.0.15

flutter_tree_pro

Flutter 樹狀選擇組件。您可以使用它來選擇樹節點。這也支援從右到左(RTL)。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
140
喜歡數
28
Pub 分數
150

安裝套件

flutter pub add flutter_tree_pro

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flutter Tree Pro 是一個可自定義的樹狀選擇元件,適用於 Flutter,讓使用者能輕鬆導航與選擇層級資料結構。它支援從右到左(RTL)版面配置,適合多語言應用程式。此套件可無縫整合至 Android、iOS、Web、macOS、Windows 與 Linux 平台。設計用於直覺的使用者互動,讓開發者能夠建立複雜的樹狀介面,例如檔案瀏覽器、組織圖表或類別選擇器。其輕量且彈性的架構確保即使面對大量資料也能順暢運作。

適用情境

  • 檔案總管介面
  • 組織架構圖顯示
  • 類別過濾系統
  • 分層數據選擇
  • 設定導航菜單

主要特色

  • RTL 支援
  • 跨平台相容性
  • 可自定義的節點樣式
  • 大型樹狀結構的高效渲染
  • 多選功能

適合對象

  • 開發階層式使用者介面的開發者
  • 需要樹狀導航的應用程式
  • 國際化應用程式
  • 複雜數據結構可視化
  • 具有共享代碼庫的 Web 和移動應用

使用建議

  • 可能需要自訂樣式以支援複雜主題
  • 極深樹狀結構帶來的效能影響
  • 有限的內建動畫
  • 需要手動處理狀態管理
  • 不適用於即時協作編輯

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

flutter_tree_pro

A Flutter tree-select widget with checkbox selection, single-select mode, RTL support, and leaf-node drag-and-drop.

Demo

flutter_tree demo

Features

  • Build tree data from flat list (DataType.DataList) or nested map (DataType.DataMap)
  • Multi-select with parent/child check-state synchronization
  • Single-select mode with initial selected node
  • Expand/collapse nodes
  • RTL layout support
  • Custom tree connector line style (TreeLineStyle)
  • Drag-and-drop for leaf nodes
    • Drop on a non-leaf node: dragged leaf becomes a child of that node
    • Drop on a leaf node: dragged leaf is inserted after target leaf as a sibling

Installation

Add dependency to your pubspec.yaml:

dependencies:
  flutter_tree_pro: ^0.0.16

Then run:

flutter pub get

Quick Start (DataList)

import 'package:flutter/material.dart';
import 'package:flutter_tree_pro/flutter_tree_pro.dart';

class TreeDemo extends StatefulWidget {
  const TreeDemo({super.key});

  @override
  State<TreeDemo> createState() => _TreeDemoState();
}

class _TreeDemoState extends State<TreeDemo> {
  final List<Map<String, dynamic>> listData = [
    {'id': 1001, 'parentId': 0, 'value': 'USA'},
    {'id': 1002, 'parentId': 1001, 'value': 'California'},
    {'id': 1003, 'parentId': 1002, 'value': 'San Francisco'},
    {'id': 1004, 'parentId': 1001, 'value': 'New York'},
  ];

  final List<Map<String, dynamic>> initialListData = [
    {'id': 1003, 'parentId': 1002, 'value': 'San Francisco'},
  ];

  List<Map<String, dynamic>> checked = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('flutter_tree_pro')),
      body: FlutterTreePro(
        listData: listData,
        initialListData: initialListData,
        isExpanded: true,
        isRTL: false,
        isSingleSelect: false,
        config: const Config(
          dataType: DataType.DataList,
          id: 'id',
          parentId: 'parentId',
          label: 'value',
          children: 'children',
          lineStyle: TreeLineStyle(
            color: Color(0xFFE0E0E0),
            width: 1.0,
            indent: 28,
            showVerticalLine: true,
            showHorizontalLine: true,
          ),
        ),
        onChecked: (items) {
          setState(() {
            checked = items;
          });
        },
      ),
    );
  }
}

Data Source Modes

DataType.DataList

Use flat list data with id + parentId and pass it through listData.

Required fields in each item (or mapped by Config):

  • id
  • parentId
  • label (for display text)
DataType.DataMap

Use nested tree data with children and pass it through treeData.

If treeData is empty and initialTreeData is provided, initialTreeData will be used as fallback root data.

API

FlutterTreePro parameters
Parameter Type Default Description
treeData List<Map<String, dynamic>> const [] Tree source for DataMap mode
listData List<Map<String, dynamic>> const [] Flat source for DataList mode
initialTreeData Map<String, dynamic> const {} Fallback root tree node when treeData is empty
initialListData List<Map<String, dynamic>> const [] Initial checked items in multi-select mode
config Config const Config() Field mapping and tree style config
onChecked Function(List<Map<String, dynamic>>) required Selection callback
isExpanded bool false Expand all nodes initially
isRTL bool false Enable right-to-left layout
isSingleSelect bool false Enable single-select mode
initialSelectValue int 0 Initial selected node ID in single-select mode
Config
Field Type Default Description
dataType DataType DataType.DataMap Data mode
id String 'id' Node ID key
parentId String 'parentId' Parent ID key
label String 'label' Display text key
value String 'value' Reserved compatibility field
children String 'children' Children key
lineStyle TreeLineStyle const TreeLineStyle() Connector line style
TreeLineStyle
Field Type Default Description
color Color Color(0xFFD9D9D9) Line color
width double 1.0 Line width
indent double 24.0 Per-level indentation
showVerticalLine bool true Show vertical connectors
showHorizontalLine bool true Show horizontal connectors

Drag-and-Drop Rules

  • Only leaf nodes can be dragged.
  • A node cannot be dropped onto itself.
  • A node cannot be dropped directly onto its current parent.
  • Drop on a leaf node inserts after that target leaf, keeping the same parent level.
  • Drop on a non-leaf node appends as the target node's child.

Notes

  • In multi-select mode, onChecked returns checked leaf nodes after internal filtering/deduplication.
  • In single-select mode, onChecked returns at most one selected node.
  • Config.value is reserved for compatibility and is not used by current select-state logic.

Example Project

See /example for a runnable demo:

cd example
flutter pub get
flutter run

License

MIT

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。