Skip to content

Commit d56702e

Browse files
committed
Review feedback round 2
1 parent a6b2b6e commit d56702e

File tree

6 files changed

+147
-192
lines changed

6 files changed

+147
-192
lines changed

packages/two_dimensional_scrollables/example/lib/tree_view/custom_tree.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class CustomTreeExampleState extends State<CustomTreeExample> {
233233

234234
@override
235235
Widget build(BuildContext context) {
236+
// This example is assumes the full screen is available.
236237
final Size screenSize = MediaQuery.sizeOf(context);
237238
final List<Widget> selectedChildren = <Widget>[];
238239
if (_selectedNode != null) {

packages/two_dimensional_scrollables/lib/src/tree_view/render_tree.dart

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class RenderTreeViewport extends RenderTwoDimensionalViewport {
3030
RenderTreeViewport({
3131
required Map<UniqueKey, TreeViewNodesAnimation> activeAnimations,
3232
required Map<int, int> rowDepths,
33-
required TreeViewTraversalOrder traversalOrder,
3433
required double indentation,
3534
required super.horizontalOffset,
3635
required super.horizontalAxisDirection,
@@ -42,15 +41,11 @@ class RenderTreeViewport extends RenderTwoDimensionalViewport {
4241
super.clipBehavior,
4342
}) : _activeAnimations = activeAnimations,
4443
_rowDepths = rowDepths,
45-
_traversalOrder = traversalOrder,
4644
_indentation = indentation,
45+
assert(indentation >= 0),
4746
assert(verticalAxisDirection == AxisDirection.down &&
4847
horizontalAxisDirection == AxisDirection.right),
49-
super(
50-
mainAxis: traversalOrder == TreeViewTraversalOrder.depthFirst
51-
? Axis.vertical
52-
: Axis.horizontal,
53-
);
48+
super(mainAxis: Axis.vertical);
5449

5550
@override
5651
TreeRowDelegateMixin get delegate => super.delegate as TreeRowDelegateMixin;
@@ -78,7 +73,7 @@ class RenderTreeViewport extends RenderTwoDimensionalViewport {
7873

7974
/// The depth of each currently active node in the tree.
8075
///
81-
/// This is used to properly set the [TreeVicinity] for the [traversalOrder].
76+
/// This is used to properly set the [TreeVicinity].
8277
Map<int, int> get rowDepths => _rowDepths;
8378
Map<int, int> _rowDepths;
8479
set rowDepths(Map<int, int> value) {
@@ -89,23 +84,6 @@ class RenderTreeViewport extends RenderTwoDimensionalViewport {
8984
markNeedsLayout();
9085
}
9186

92-
/// The order in which child nodes of the tree will be traversed.
93-
///
94-
/// The default traversal order is [TreeViewTraversalOrder.depthFirst].
95-
TreeViewTraversalOrder get traversalOrder => _traversalOrder;
96-
TreeViewTraversalOrder _traversalOrder;
97-
set traversalOrder(TreeViewTraversalOrder value) {
98-
if (_traversalOrder == value) {
99-
return;
100-
}
101-
_traversalOrder = value;
102-
// Changing mainAxis will call markNeedsLayout.
103-
mainAxis = switch (value) {
104-
TreeViewTraversalOrder.depthFirst => Axis.vertical,
105-
TreeViewTraversalOrder.breadthFirst => Axis.horizontal,
106-
};
107-
}
108-
10987
/// The number of pixels by which child nodes will be offset in the cross axis
11088
/// based on [rowDepths].
11189
///

packages/two_dimensional_scrollables/lib/src/tree_view/tree.dart

Lines changed: 23 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ import 'tree_core.dart';
1111
import 'tree_delegate.dart';
1212
import 'tree_span.dart';
1313

14-
// SHARED WITH FRAMEWORK - TreeViewNode (SliverTreeNode), TreeViewController (SliverTreeController)
15-
// Should not deviate from the core components of the framework.
14+
// The classes in these files follow the same pattern as the one dimensional
15+
// sliver tree in the framework.
1616
//
17-
// These classes share the same surface as SliverTree in the framework since
18-
// they are not currently available on the stable branch. After rolling to
19-
// stable, these classes may be deprecated, or more likely made to be
20-
// typedefs/subclasses of the framework core tree components. They could also
21-
// live on if at a later date the 2D TreeView deviates or adds special features
22-
// not relevant to the 1D sliver components of the framework.
17+
// After rolling to stable, these classes may be deprecated, or more likely
18+
// made to be typedefs/subclasses of the framework core tree components. They
19+
// could also live on if at a later date the 2D TreeView deviates or adds
20+
// special features not relevant to the 1D sliver components of the framework.
2321

2422
const double _kDefaultRowExtent = 40.0;
2523

@@ -43,9 +41,6 @@ class TreeViewNode<T> {
4341
/// The subject matter of the node.
4442
///
4543
/// Must correspond with the type of [TreeView].
46-
///
47-
/// The content is used to generate a unique [Key] in
48-
/// [TreeView.defaultTreeNodeBuilder] for maintain animation performance.
4944
T get content => _content;
5045
final T _content;
5146

@@ -275,11 +270,14 @@ class TreeViewController {
275270
}
276271
}
277272

278-
// END of framework shared classes.
273+
// END of shared surfaces from the framework.
279274

280275
/// A widget that displays [TreeViewNode]s that expand and collapse in a
281276
/// vertically and horizontally scrolling [TreeViewport].
282277
///
278+
/// The type [T] correlates to the type of [TreeView] and [TreeViewNode],
279+
/// representing the type of [TreeViewNode.content].
280+
///
283281
/// The rows of the tree are laid out on demand by the [TreeViewport]'s render
284282
/// object, using [TreeView.treeNodeBuilder]. This will only be called for the
285283
/// nodes that are visible, or within the [TreeViewport.cacheExtent].
@@ -296,8 +294,7 @@ class TreeViewController {
296294
///
297295
/// Each active node of the tree will have a [TreeVicinity], representing the
298296
/// resolved row index of the node, based on what nodes are active, as well as
299-
/// the depth. This vicinity is used to traverse the tree as indicated by
300-
/// [traversalOrder].
297+
/// the depth.
301298
///
302299
/// A [TreeView] only supports a vertical axis direction of
303300
/// [AxisDirection.down] and a horizontal axis direction of
@@ -313,7 +310,6 @@ class TreeView<T> extends StatefulWidget {
313310
this.controller,
314311
this.onNodeToggle,
315312
this.toggleAnimationStyle,
316-
this.traversalOrder = TreeViewTraversalOrder.depthFirst,
317313
this.indentation = TreeViewIndentationType.standard,
318314
this.primary,
319315
this.mainAxis = Axis.vertical,
@@ -378,15 +374,6 @@ class TreeView<T> extends StatefulWidget {
378374
/// To disable the tree animation, use [AnimationStyle.noAnimation].
379375
final AnimationStyle? toggleAnimationStyle;
380376

381-
/// The order in which [TreeViewNode]s are visited.
382-
///
383-
/// This value will influence [TreeViewport.mainAxis] so nodes are traversed
384-
/// properly when they are converted to a [TreeVicinity] in the context of the
385-
/// active nodes of the tree.
386-
///
387-
/// Defaults to [TreeViewTraversalOrder.depthFirst].
388-
final TreeViewTraversalOrder traversalOrder;
389-
390377
/// The number of pixels children will be offset by in the cross axis based on
391378
/// their [TreeViewNode.depth].
392379
///
@@ -507,6 +494,13 @@ class TreeView<T> extends StatefulWidget {
507494
/// Defaults to true.
508495
final bool addRepaintBoundaries;
509496

497+
/// The default [AnimationStyle] used for node expand and collapse animations,
498+
/// when one has not been provided in [toggleAnimationStyle].
499+
static AnimationStyle defaultToggleAnimationStyle = AnimationStyle(
500+
curve: defaultAnimationCurve,
501+
duration: defaultAnimationDuration,
502+
);
503+
510504
/// A default of [Curves.linear], which is used in the tree's expanding and
511505
/// collapsing node animation.
512506
static const Curve defaultAnimationCurve = Curves.linear;
@@ -553,7 +547,8 @@ class TreeView<T> extends StatefulWidget {
553547
);
554548
}
555549

556-
/// Returns the default tree row for a given [TreeViewNode].
550+
/// Default builder for the widget representing a given [TreeViewNode] in the
551+
/// tree.
557552
///
558553
/// Used by [TreeView.treeNodeBuilder].
559554
///
@@ -582,7 +577,7 @@ class TreeView<T> extends StatefulWidget {
582577
dimension: 30.0,
583578
child: node.children.isNotEmpty
584579
? AnimatedRotation(
585-
key: Key('$index - ${node.content}'),
580+
key: Key('$index'),
586581
turns: node.isExpanded ? 0.25 : 0.0,
587582
duration: animationDuration,
588583
curve: animationCurve,
@@ -744,11 +739,7 @@ class _TreeViewState<T> extends State<TreeView<T>>
744739
Widget child = widget.treeNodeBuilder(
745740
context,
746741
node,
747-
widget.toggleAnimationStyle ??
748-
AnimationStyle(
749-
curve: TreeView.defaultAnimationCurve,
750-
duration: TreeView.defaultAnimationDuration,
751-
),
742+
widget.toggleAnimationStyle ?? TreeView.defaultToggleAnimationStyle,
752743
);
753744

754745
if (widget.addRepaintBoundaries) {
@@ -761,7 +752,6 @@ class _TreeViewState<T> extends State<TreeView<T>>
761752
return widget.treeRowBuilder(_activeNodes[vicinity.row]);
762753
},
763754
addAutomaticKeepAlives: widget.addAutomaticKeepAlives,
764-
traversalOrder: widget.traversalOrder,
765755
indentation: widget.indentation.value,
766756
);
767757
}
@@ -971,7 +961,6 @@ class _TreeView extends TwoDimensionalScrollView {
971961
super.clipBehavior,
972962
required TwoDimensionalIndexedWidgetBuilder nodeBuilder,
973963
required TreeVicinityToRowBuilder rowBuilder,
974-
this.traversalOrder = TreeViewTraversalOrder.depthFirst,
975964
required this.activeAnimations,
976965
required this.rowDepths,
977966
required this.indentation,
@@ -989,7 +978,6 @@ class _TreeView extends TwoDimensionalScrollView {
989978

990979
final Map<UniqueKey, TreeViewNodesAnimation> activeAnimations;
991980
final Map<int, int> rowDepths;
992-
final TreeViewTraversalOrder traversalOrder;
993981
final double indentation;
994982

995983
@override
@@ -1008,7 +996,6 @@ class _TreeView extends TwoDimensionalScrollView {
1008996
clipBehavior: clipBehavior,
1009997
activeAnimations: activeAnimations,
1010998
rowDepths: rowDepths,
1011-
traversalOrder: traversalOrder,
1012999
indentation: indentation,
10131000
);
10141001
}
@@ -1030,15 +1017,10 @@ class TreeViewport extends TwoDimensionalViewport {
10301017
super.clipBehavior,
10311018
required this.activeAnimations,
10321019
required this.rowDepths,
1033-
this.traversalOrder = TreeViewTraversalOrder.depthFirst,
10341020
required this.indentation,
10351021
}) : assert(verticalAxisDirection == AxisDirection.down &&
10361022
horizontalAxisDirection == AxisDirection.right),
1037-
super(
1038-
mainAxis: traversalOrder == TreeViewTraversalOrder.depthFirst
1039-
? Axis.vertical
1040-
: Axis.horizontal,
1041-
);
1023+
super(mainAxis: Axis.vertical);
10421024

10431025
/// The currently active [TreeViewNode] animations.
10441026
///
@@ -1048,16 +1030,8 @@ class TreeViewport extends TwoDimensionalViewport {
10481030
final Map<UniqueKey, TreeViewNodesAnimation> activeAnimations;
10491031

10501032
/// The depth of each active [TreeNode].
1051-
///
1052-
/// This is used to properly traverse nodes according to
1053-
/// [traversalOrder].
10541033
final Map<int, int> rowDepths;
10551034

1056-
/// The order in which child nodes of the tree will be traversed.
1057-
///
1058-
/// The default traversal order is [TreeViewTraversalOrder.depthFirst].
1059-
final TreeViewTraversalOrder traversalOrder;
1060-
10611035
/// The number of pixels by which child nodes will be offset in the cross axis
10621036
/// based on their [TreeViewNode.depth].
10631037
///
@@ -1070,7 +1044,6 @@ class TreeViewport extends TwoDimensionalViewport {
10701044
return RenderTreeViewport(
10711045
activeAnimations: activeAnimations,
10721046
rowDepths: rowDepths,
1073-
traversalOrder: traversalOrder,
10741047
indentation: indentation,
10751048
horizontalOffset: horizontalOffset,
10761049
horizontalAxisDirection: horizontalAxisDirection,
@@ -1091,7 +1064,6 @@ class TreeViewport extends TwoDimensionalViewport {
10911064
renderObject
10921065
..activeAnimations = activeAnimations
10931066
..rowDepths = rowDepths
1094-
..traversalOrder = traversalOrder
10951067
..indentation = indentation
10961068
..horizontalOffset = horizontalOffset
10971069
..horizontalAxisDirection = horizontalAxisDirection

packages/two_dimensional_scrollables/lib/src/tree_view/tree_core.dart

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import 'package:flutter/widgets.dart';
66

77
import 'tree.dart';
88

9-
// SHARED WITH FRAMEWORK (whole file)
10-
// Should not deviate from the core components of the framework.
9+
// The classes in these files follow the same pattern as the one dimensional
10+
// sliver tree in the framework.
1111
//
12-
// These classes share the same surface as SliverTree in the framework since
13-
// they are not currently available on the stable branch. After rolling to
14-
// stable, these classes may be deprecated, or more likely made to be
15-
// typedefs/subclasses of the framework core tree components. They could also
16-
// live on if at a later date the 2D TreeView deviates or adds special features
17-
// not relevant to the 1D sliver components of the framework.
12+
// After rolling to stable, these classes may be deprecated, or more likely
13+
// made to be typedefs/subclasses of the framework core tree components. They
14+
// could also live on if at a later date the 2D TreeView deviates or adds
15+
// special features not relevant to the 1D sliver components of the framework.
1816

1917
/// Signature for a function that is called when a [TreeViewNode] is toggled,
2018
/// changing its expanded state.
@@ -94,27 +92,6 @@ typedef TreeViewNodesAnimation = ({
9492
double value,
9593
});
9694

97-
/// Traversal order pattern for [TreeViewNode]s that are children of a
98-
/// [TreeView].
99-
enum TreeViewTraversalOrder {
100-
/// Pre-order depth traversal.
101-
///
102-
/// This traversal pattern will visit each given [TreeViewNode] before
103-
/// visiting each of its children.
104-
///
105-
/// This is the default traversal pattern for [TreeView.traversalOrder].
106-
depthFirst,
107-
108-
/// Lever order traversal.
109-
///
110-
/// This traversal pattern will visit each node that exists at the same
111-
/// [TreeViewNode.depth], before progressing to the next depth of nodes in
112-
/// the tree.
113-
///
114-
/// Can be used in [TreeView.traversalOrder], which defaults to [depthFirst].
115-
breadthFirst,
116-
}
117-
11895
/// The style of indentation for [TreeViewNode]s in a [TreeView], as handled
11996
/// by [RenderTreeViewport].
12097
///

packages/two_dimensional_scrollables/test/tree_view/render_tree_test.dart

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ void main() {
9494
activeAnimations: const <UniqueKey, TreeViewNodesAnimation>{},
9595
rowDepths: const <int, int>{},
9696
indentation: 0.0,
97-
traversalOrder: TreeViewTraversalOrder.depthFirst,
9897
childManager: _NullBuildContext(),
9998
);
10099
},
@@ -123,7 +122,6 @@ void main() {
123122
activeAnimations: const <UniqueKey, TreeViewNodesAnimation>{},
124123
rowDepths: const <int, int>{},
125124
indentation: 0.0,
126-
traversalOrder: TreeViewTraversalOrder.depthFirst,
127125
childManager: _NullBuildContext(),
128126
);
129127
},
@@ -138,50 +136,6 @@ void main() {
138136
expect(treeViewport, isNull);
139137
});
140138

141-
test('Sets mainAxis based on traversal order', () {
142-
RenderTreeViewport treeViewport = RenderTreeViewport(
143-
verticalOffset: TestOffset(),
144-
verticalAxisDirection: AxisDirection.down,
145-
horizontalOffset: TestOffset(),
146-
horizontalAxisDirection: AxisDirection.right,
147-
delegate: TreeRowBuilderDelegate(
148-
rowCount: 0,
149-
nodeBuilder: (_, __) => const SizedBox(),
150-
rowBuilder: (_) => const TreeRow(
151-
extent: FixedTreeRowExtent(40.0),
152-
),
153-
),
154-
activeAnimations: const <UniqueKey, TreeViewNodesAnimation>{},
155-
rowDepths: const <int, int>{},
156-
indentation: 0.0,
157-
traversalOrder: TreeViewTraversalOrder.depthFirst,
158-
childManager: _NullBuildContext(),
159-
);
160-
expect(treeViewport.mainAxis, Axis.vertical);
161-
expect(treeViewport.traversalOrder, TreeViewTraversalOrder.depthFirst);
162-
163-
treeViewport = RenderTreeViewport(
164-
verticalOffset: TestOffset(),
165-
verticalAxisDirection: AxisDirection.down,
166-
horizontalOffset: TestOffset(),
167-
horizontalAxisDirection: AxisDirection.right,
168-
delegate: TreeRowBuilderDelegate(
169-
rowCount: 0,
170-
nodeBuilder: (_, __) => const SizedBox(),
171-
rowBuilder: (_) => const TreeRow(
172-
extent: FixedTreeRowExtent(40.0),
173-
),
174-
),
175-
activeAnimations: const <UniqueKey, TreeViewNodesAnimation>{},
176-
rowDepths: const <int, int>{},
177-
indentation: 0.0,
178-
traversalOrder: TreeViewTraversalOrder.breadthFirst,
179-
childManager: _NullBuildContext(),
180-
);
181-
expect(treeViewport.mainAxis, Axis.horizontal);
182-
expect(treeViewport.traversalOrder, TreeViewTraversalOrder.breadthFirst);
183-
});
184-
185139
testWidgets('TreeRow gesture hit testing', (WidgetTester tester) async {
186140
int tapCounter = 0;
187141
final List<String> log = <String>[];

0 commit comments

Comments
 (0)