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
88 lines (78 loc) · 2.35 KB
/
node_widget.dart
File metadata and controls
88 lines (78 loc) · 2.35 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
78
79
80
81
82
83
84
85
86
87
88
// 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;
final Widget? primaryIcon;
final Widget? secondaryIcon;
const NodeWidget({
Key? key,
required this.treeNode,
this.indent,
required this.state,
this.iconSize,
this.primaryIcon,
this.secondaryIcon,
}) : 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
? widget.secondaryIcon ?? Icon(Icons.expand_more)
: widget.primaryIcon ?? Icon(Icons.chevron_right);
var onIconPressed = _isLeaf ? null : () => setState(() => widget.state.toggleNodeExpanded(widget.treeNode.key!));
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Material(
child: InkWell(
borderRadius: BorderRadius.circular(2.00),
child: SizedBox.square(
dimension: widget.iconSize ?? 24.0,
child: icon,
),
onTap: onIconPressed,
),
),
widget.treeNode.content,
],
),
if (_isExpanded && !_isLeaf)
Padding(
padding: EdgeInsets.only(left: widget.indent!),
child: buildNodes(
widget.treeNode.children!,
widget.indent,
widget.state,
widget.iconSize,
widget.primaryIcon,
widget.secondaryIcon,
),
)
],
);
}
}