Aus öffentlichen Paketdaten erstellte Orientierung.
Ein Flutter-Paket, das zur Visualisierung von Baum-Datenstrukturen in einer hierarchischen Benutzeroberfläche entwickelt wurde. Es ermöglicht Entwicklern, verschachtelte Daten als interaktive Baumansichten darzustellen und unterstützt dynamisches Erweitern und Zusammenfalten von Knoten. Das Paket betont eine saubere, rekursive Rendering-Logik und ist für Leistung mit großen Datensätzen optimiert. Ideal für Anwendungen, die strukturierte Datenrepräsentation erfordern, wie Dateiexplorer, Organigramme oder Kategorienhierarchien. Aufbauend auf Flutter's Widget-System, integriert es sich nahtlos über alle wichtigen Plattformen.
Anwendungsfälle
Anzeige von Dateisystemverzeichnissen
Darstellung von Organigrammen
Kategorie- und Unterkategorienhierarchien anzeigen
Konfigurationsbäume erstellen
Visualisierung von JSON- oder XML-Datenstrukturen
Hauptmerkmale
rekursive Knoten-Rendern
Erweiterbare und zusammenfaltbare Knoten
Anpassbare Knoten-Stilierung
Unterstützung für tiefes Nesting
Plattformübergreifende Kompatibilität
Effiziente Rendern für große Bäume
Geeignet für
Entwickler, die hierarchische Daten-Schnittstellen erstellen
Apps, die interaktive Baumnavigation benötigen
Projekte mit verschachtelten Datenmodellen
UIs, die eine visuelle Baumstruktur erfordern
Flutter-Anwendungen für mehrere Plattformen
Hinweise
Kann eine Optimierung für sehr große Bäume erfordern
Benutzerdefinierte Stile erfordern ein Verständnis von Flutter-Widgets
Die Leistung hängt von der Komplexität des Knotens ab
Original-README
Originaler README-Schnappschuss aus dem verknüpften Quell-Repository. Aktuelle Inhalte finden Sie im Repository.
recursive_tree_flutter
Languages:
The recursive_tree_flutter library helps build a tree data structure and visualizes it as an inheritance tree (stack view or expandable tree view). While most tree-view libraries focus on the interface, recursive_tree_flutter prioritizes the tree data structure, allowing it to support various special UI styles - that's the strength of this library. For example, it can update the tree when a node is selected, return a list of chosen nodes/leaves, return a list of favorite nodes...
Various functions for tree operations, such as finding nodes, searching with text, updating multiple choice/single choice trees, etc.
Allows lazy-loading to expand the tree at runtime.
The tree data structure can be used independently from the Flutter UI.
Visualizes the tree structure using Flutter.
Allows customization of the Flutter UI to suit specific requirements.
Contents
Tree Data Structure (Dart code)
Inspired by the structure of a directory tree on a computer, there are two types of nodes: directories and files. A directory can contain multiple files and other directories, and a file is the smallest level that cannot contain anything else.
Similarly to the directory tree structure on a computer, recursive_tree_flutter will build a tree data structure that includes inner nodes and leaf nodes.
AbsNodeType: An abstract class representing the data type of a node. A node can be either an inner node or a leaf node. This class has the following properties:
id: required, dynamic.
title: required, String.
isInner: boolean, default is true.
isUnavailable: boolean, default is false.
isChosen: nullable boolean, default is false.
isExpanded: boolean, default is false.
isFavorite: boolean, default is false.
isShowedInSearching: boolean, default is true. Also known as isDisplayable, được sử dụng used when the UI tree has a search function.
clone(): abstract method, T extends AbsNodeType. Allows cloning the object.
parent: required, TreeType<T>?. If parent == null, it means we are at the root of the entire tree.
isChildrenLoadedLazily: boolean, default is false. Only used if the current tree is lazy-loading, indicating whether the children have been loaded before or not.
isLeaf: Is current tree at a leaf node?
isRoot: Is current tree at the root node?
clone(tree, parent): static method. Allows cloning a tree.
searchLeavesWithTitleDFS(tree, text, result): Searches for all trees whose root title data contains the searching text using the DFS algorithm. The results are stored in the result variable.
returnChosenLeaves(tree, result): Searches for all leaves whose title data contains the searching text using the DFS algorithm. The results are stored in the result variable.
returnFavoriteNodes(tree, result): Returns all nodes that have been added to the favorite list. The results are stored in the result variable.
findRightmostOfABranch(tree): (Not important) Finds the rightmost node of the current tree branch (a tree with a current level minus 1). This function is used in the VTS Department Tree to determine which node is at the bottom of the branch, so its leading widget will be slightly different.
updateAllUnavailableNodes(tree): Updates the isUnavailable property of all nodes in the current tree. Suppose when parsing data for the first time, some leaves will be unavailable, and we need to update the affected inner nodes. The function returns true if the tree is available (chosenable), otherwise false.
We can see that NodeWidget is a StatefulWidget built recursively and wrapped by SingleChildScrollView to provide scrolling capability to the tree. Updating the tree (data) will change the state/UI of the NodeWidget - this can be done using setState or Provider for management. NodeWidget will inherit ExpandableTreeMixin (as shown in the example VTSDepartmentTreeWidget using setState) with some functions like:
initTree(): Initializes the tree (data) (called in initState()).
initRotationController(): Initializes the rotationController variable used to create an animation effect when expanding the UI tree (called in initState()).
disposeRotationController().
buildView(): Builds the UI of the tree (already written).
buildNode(): Builds the UI of a node (must be implemented). This function allows developers to freely customize the UI in unlimited ways.
buildChildrenNodes(): Builds the child nodes with animation for expansion (already written).
generateChildrenNodesWidget(): Returns List<NodeWidget>, must be implemented (an example is provided in the function documentation).
toggleExpansion(): Determines whether to collapse/expand the child nodes.
updateStateToggleExpansion(): Updates the state after performing the collapse/expand action.
BSD-3-Clause License
Copyright (c) 2023, ViettelSolutionsRedistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributionsin binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.