This repository was archived by the owner on Oct 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 529
Expand file tree
/
Copy pathnode_widget.dart
More file actions
77 lines (67 loc) · 1.96 KB
/
node_widget.dart
File metadata and controls
77 lines (67 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2020 the Dart project authors.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
import 'package:flutter/material.dart';
import 'builder.dart';
import 'primitives/tree_controller.dart';
import 'primitives/tree_node.dart';
/// Widget that displays one [TreeNode] and its children.
class NodeWidget extends StatefulWidget {
final TreeNode treeNode;
final double? indent;
final double? iconSize;
final TreeController state;
const NodeWidget(
{Key? key,
required this.treeNode,
this.indent,
required this.state,
this.iconSize})
: super(key: key);
@override
_NodeWidgetState createState() => _NodeWidgetState();
}
class _NodeWidgetState extends State<NodeWidget> {
bool get _isLeaf {
return widget.treeNode.children == null ||
widget.treeNode.children!.isEmpty;
}
bool get _isExpanded {
return widget.state.isNodeExpanded(widget.treeNode.key!);
}
@override
Widget build(BuildContext context) {
var icon = _isLeaf
? null
: _isExpanded
? Icons.expand_more
: Icons.chevron_right;
var onIconPressed = _isLeaf
? null
: () => setState(
() => widget.state.toggleNodeExpanded(widget.treeNode.key!));
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
IconButton(
iconSize: widget.iconSize ?? 24.0,
icon: Icon(icon),
onPressed: onIconPressed,
),
widget.treeNode.content,
],
),
if (_isExpanded && !_isLeaf)
Padding(
padding: EdgeInsetsDirectional.only(start: widget.indent!),
child: buildNodes(widget.treeNode.children!, widget.indent,
widget.state, widget.iconSize),
)
],
);
}
}