DirectoryTreeController<T> constructor

DirectoryTreeController<T>({
  1. DirectoryTree<T>? tree,
  2. ExpansionState expansion = const ExpansionState.collapsed(),
  3. SelectionState selection = const SelectionState.empty(mode: SelectionMode.multiple),
  4. SelectionState checks = const SelectionState.empty(mode: SelectionMode.multiple),
  5. bool selectable(
    1. TreeNode<T> node
    )?,
  6. String query = '',
  7. bool caseSensitiveQuery = false,
  8. TreeFilter? filter,
  9. bool revealMatches = true,
  10. bool compactFolders = false,
  11. bool showRoots = true,
  12. DirectoryChildrenLoader<T>? loadChildren,
  13. DirectoryLoadErrorCallback? onLoadError,
})

Creates a controller for tree (an empty tree when null).

  • expansion is the initial requested expansion; every directory starts collapsed by default. With an active query or filter, the rows show it plus the ancestors of the matches.
  • selection and checks are the initial highlight selection and checkbox state, both in SelectionMode.multiple by default. Ids that tree does not contain are dropped, and a selected directory inside a compacted chain is stored as the chain's deepest directory, as selection says.
  • selectable decides which nodes the selection commands may select; every node by default. It does not affect checks. It must be pure and cheap, since selectAll and extendSelection call it per row.
  • query, caseSensitiveQuery, filter, and revealMatches: see the properties of the same names.
  • compactFolders and showRoots: see the properties of the same names.
  • loadChildren makes directories without children lazily loadable; see DirectoryChildrenLoader. onLoadError is told about failed loads (see DirectoryLoadErrorCallback).

With a loader and showRoots false, every top-level directory without children starts loading right away.

Implementation

DirectoryTreeController({
  DirectoryTree<T>? tree,
  ExpansionState expansion = const ExpansionState.collapsed(),
  SelectionState selection = const SelectionState.empty(
    mode: SelectionMode.multiple,
  ),
  SelectionState checks = const SelectionState.empty(
    mode: SelectionMode.multiple,
  ),
  this._selectable,
  String query = '',
  bool caseSensitiveQuery = false,
  TreeFilter? filter,
  bool revealMatches = true,
  this._compactFolders = false,
  this._showRoots = true,
  DirectoryChildrenLoader<T>? loadChildren,
  this._onLoadError,
}) : _tree = tree ?? DirectoryTree<T>.empty(),
     _requested = expansion,
     _query = query,
     _caseSensitiveQuery = caseSensitiveQuery,
     _filter = filter,
     _revealMatches = revealMatches,
     _loader = loadChildren {
  if (kFlutterMemoryAllocationsEnabled) {
    ChangeNotifier.maybeDispatchObjectCreation(this);
  }
  _selection = selection.prune(_tree);
  _checks = checks.prune(_tree);
  _parsedQuery = _parseQuery(query, caseSensitive: caseSensitiveQuery);
  _effectiveFilter = _combineFilters(_parsedQuery, filter);
  _rows = _flatten(
    expansion,
    expandMatches: _effectiveFilter != null && revealMatches,
  );
  _lastRowsChange = const TreeRowsChange.reset(previous: null);
  _selectChainEnds();
  _loadHiddenRoots();
  // Nobody listens yet, so the statuses set above need no notification.
  _dirty = false;
}