Tree view
A tree lets readers explore a hierarchy without leaving the current view. Use short, distinct names so a reader can follow the path back to a parent.
Browse folders
#Expand Files to reveal Notes and Maps. Move to Maps, then return to Files and close the branch.
components/tree-view/appliance/browse_folders.dart
import 'package:flutter/widgets.dart';
import 'package:appliance_ui/appliance_ui.dart';
class BrowseFolders extends StatefulWidget {
const BrowseFolders({super.key});
@override
State<BrowseFolders> createState() => _BrowseFoldersState();
}
class _BrowseFoldersState extends State<BrowseFolders> {
final folders = DesignTreeController<String>(
roots: const ['Files'],
childrenOf: (folder) =>
folder == 'Files' ? const ['Notes', 'Maps'] : const [],
);
@override
void dispose() {
folders.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) => ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 440),
child: SingleChildScrollView(
child: ApplianceTree<String>(
semanticLabel: 'Folders',
controller: folders,
labelOf: (folder) => folder,
),
),
);
}
Parameters
ApplianceTree API ↗controller- Holds the tree’s nodes, expanded branches and selection.
labelOf- A node's words.
onActivate- Opens a node (Enter, a press).
semanticLabel- Its name for a screen reader.
style- Overrides the component’s themed appearance for this instance.
Shared behaviour
- Keyboard and focus. Tab into the tree. Use the horizontal arrows to open or close a branch and Up or Down to move between visible rows.
- Screen readers. Read the folder names and their expanded states. After closing Files, its children leave the reading order.
- Direction and type. In RTL the arrow toward a child changes direction. Try the tree at the larger text setting and compare the indentation at each level.