flutter_directory_tree library
A production-ready file system explorer for Flutter applications.
Key Features:
- Virtualization: Efficiently renders huge trees using flattening and virtual scrolling.
- State Management: Preserves selection and expansion states across data refreshes.
- Interactivity: Built-in keyboard navigation (arrows, shift-select), context menus, and drag-and-drop hooks.
- Theming: Fully customizable look via DirectoryTreeThemeData, with sensible defaults for Light/Dark modes.
Getting Started:
- Create a DirectoryTreeController with your TreeData.
- Display it using the all-in-one DirectoryTreePanel or build a custom view with DirectoryTreeView.
See individual classes for detailed behavior documentation.
Classes
- AlphaSortDelegate
- A standard sorter: folders first, then files, sorted alphabetically.
- ClearSelectionIntent
- Intent to clear all selection.
- CollapseNodeIntent
- Intent to collapse a specific node.
- ContextMenuDelegate
- Abstract strategy for handling secondary clicks (right-click) on tree nodes.
- DefaultFlattenStrategy
- Traverses the tree depth-first, respecting expansion state.
-
DirectoryTreeAction<
T extends Intent> - Connects Intents from the Flutter Actions system to the DirectoryTreeController.
- DirectoryTreeController
- The central coordinator for the directory tree's state and logic.
- DirectoryTreeDefaults
- Utility for generating default theme data based on the app's brightness.
- DirectoryTreePanel
- A complete, ready-to-use directory tree component.
- DirectoryTreeTheme
- InheritedWidget that propagates DirectoryTreeThemeData down the tree.
- DirectoryTreeThemeData
- Defines the visual properties of the directory tree.
- DirectoryTreeToolbar
- A utility bar providing filter input and bulk expansion controls.
- DirectoryTreeView
- The primary widget for rendering the directory tree.
- ExpandNodeIntent
- Intent to expand a specific node.
- ExpansionController
- Manages the state of expanded folders.
- ExpansionSet
- Tracks which folders are currently open.
- FlattenStrategy
- Determines how the hierarchical tree is converted into a linear list for rendering.
- IconProvider
- Strategy for resolving icons based on node state and file type.
- ListDiff
- Represents the delta required to transform one list of nodes into another.
- MaterialContextMenuDelegate
- A standard implementation that displays a Material showMenu on right-click or long-press.
- MaterialIconProvider
- Default implementation using standard Material Design icons.
- NodeAction
- Defines a single actionable item in a context menu.
- NodeVisualState
- Immutable snapshot of a node's visual state during a render cycle.
- RevealNodeIntent
- Intent to reveal a hidden node (by expanding parents) and optionally select it.
- SelectionController
- Manages single or multiple selection states.
- SelectionSet
- Tracks selected items and enforces selection modes.
- SelectionShortcuts
- Adds keyboard navigation and selection support to the tree.
- SelectOnlyIntent
- Intent to select a single node, clearing other selections.
- SortDelegate
- Controls how children of a folder are ordered during flattening.
- SortedFlattenStrategy
- Wraps the default traversal but sorts children using a SortDelegate before visiting them.
- ToggleNodeIntent
- Intent to toggle the expansion state of a node.
- TreeBuilder
- The engine for constructing a deterministic, normalized directory tree.
- TreeData
- Holds the complete state of the directory tree at a specific point in time.
- TreeEntry
- Defines a single item to be placed in the tree.
- TreeNode
- A vertex in the TreeData graph representing a file or folder.
- TreeNodeTile
- A standard row widget that respects the active DirectoryTreeTheme.
- VisibleNode
- A lightweight view model representing a single row in the rendered tree list.
Enums
- FolderSelection
- Represents the tri-state selection status of a folder.
- NodeType
- Describes the type of a node in the tree graph.
- SelectionMode
- Defines how many items can be selected at once.
- SelectionOrigin
- Indicates how a folder came to exist in the tree.
Functions
-
ancestorChain(
TreeData data, String nodeId) → List< String> -
Finds the sequence of parent nodes leading to
nodeId. -
basename(
String pathOrName) → String - Returns the last part of a path (the filename).
-
compileFilter(
String? query) → Predicate - Converts a user-typed query string into a testable predicate.
-
diffVisibleNodes(
List< VisibleNode> before, List<VisibleNode> after) → ListDiff - Computes the difference between two flat lists to enable smooth UI animations using ListDiff.
-
extensionLower(
String pathOrName) → String -
Returns the file extension in lowercase (e.g.,
.dart). -
findByVirtualPath(
TreeData data, String virtualPath) → String? - Searches for a node with the exact virtual path.
-
folderSelection(
DirectoryTreeController controller, String folderId) → FolderSelection - Computes the selection state (Checked, Unchecked, Indeterminate) for a folder.
-
hasAnyExtension(
String candidate, Iterable< String> extensions) → bool -
Checks if
candidatehas one of the providedextensions. -
revealAndSelect(
DirectoryTreeController controller, {String? nodeId, String? virtualPath}) → Future< void> - Convenience wrapper to reveal and select a node in one step.
-
schedulePreserveScrollOffset(
{required ScrollController controller, required List< VisibleNode> before, required List<VisibleNode> after, required double rowExtent}) → void - Adjusts the scroll position to keep the user's view stable during tree updates.
-
showDirectoryTreePicker(
{required BuildContext context, required DirectoryTreeController controller, bool allowMultiple = false, bool foldersOnly = false, String confirmLabel = 'Select', String title = 'Select'}) → Future< Set< String> > - Displays a modal dialog for selecting files or folders.
Typedefs
- ExpanderBuilder = Widget Function(BuildContext context, VisibleNode node, bool isExpanded, VoidCallback onPressed)
- Signature for building the expand/collapse chevron.
- NodeBuilder = Widget Function(BuildContext context, VisibleNode node, NodeVisualState state)
- Signature for widgets that render a single tree row.
- Predicate = bool Function(String name, String? ext)
- A function that returns true if a node matches the criteria.