Skip to content

Commit 2d5c203

Browse files
authored
Merge pull request #63 from dukefirehawk/migrated/bug-fix-5
Fixed material tree runtime exception
2 parents d2be0c9 + 9cfe168 commit 2d5c203

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

angular_components/lib/src/material_tree/group/material_tree_group.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,18 @@ class MaterialTreeGroupComponent<T> extends MaterialTreeNode<T?>
130130
padding += checkboxWidth;
131131
}
132132
}
133+
133134
return '${padding}px';
134135
}
135136

137+
String getLastIndent(OptionGroup group) {
138+
if (group.isNotEmpty) {
139+
return getIndent(group.last);
140+
}
141+
142+
return '0px';
143+
}
144+
136145
void handleExpansion(Event e, Object option) {
137146
toggleExpansion(option as T);
138147
e.stopPropagation();

angular_components/lib/src/material_tree/group/material_tree_group.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</li>
8484
<li *ngIf="viewMoreLinkVisible">
8585
<div class="view-more-link-item"
86-
[style.padding-left]="getIndent(visibleGroup.last)">
86+
[style.padding-left]="getLastIndent(visibleGroup)">
8787
<div class="material-tree-shift"
8888
[style.padding-left]="fixedPadding">
8989
<a class="view-more-link"

angular_components/lib/src/material_tree/material_tree_node.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ class MaterialTreeNode<T> {
4242
MaterialTreeNode(this._root, this._changeDetector,
4343
{IsExpandable<T>? isExpandable}) {
4444
_group = _EMPTY_OPTION_GROUP;
45+
4546
if (!_root.supportsHierarchy) {
4647
_isExpandable = (_) => false;
4748
_parent = _NotAParent();
4849
} else {
4950
_isExpandable = isExpandable ?? hasChildren;
50-
51-
// TODO: Type not match
52-
_parent = _root.options as Parent<T, Iterable<OptionGroup<T>>>;
51+
_parent = _root.options as Parent<T, List<OptionGroup<T>>>;
5352
}
5453
// TODO(google).
5554
final Object? options = _root.options;

examples/material_tree_example/lib/src/material_tree_demo_options.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ final SelectionOptions filterableNestedOptions =
7979

8080
/// An example implementation of [SelectionOptions] with [Parent].
8181
class _NestedSelectionOptions<T> extends SelectionOptions<T>
82-
implements Parent<T, List<OptionGroup<T>>?> {
82+
implements Parent<T, List<OptionGroup<T>>> {
8383
final Map<T, List<OptionGroup<T>>> _children;
8484

8585
_NestedSelectionOptions(List<OptionGroup<T>> options, this._children)
@@ -89,8 +89,9 @@ class _NestedSelectionOptions<T> extends SelectionOptions<T>
8989
bool hasChildren(T item) => _children.containsKey(item);
9090

9191
@override
92-
DisposableFuture<List<OptionGroup<T>>?> childrenOf(T parent, [_]) {
93-
return DisposableFuture<List<OptionGroup<T>>?>.fromValue(_children[parent]);
92+
DisposableFuture<List<OptionGroup<T>>> childrenOf(T parent, [_]) {
93+
return DisposableFuture<List<OptionGroup<T>>>.fromValue(
94+
_children[parent] ?? []);
9495
}
9596
}
9697

@@ -102,7 +103,7 @@ class _NestedFilterableSelectionOptions<T extends String>
102103
@override
103104
String? currentQuery;
104105

105-
List<OptionGroup<T>>? _unfilteredOptionGroups;
106+
List<OptionGroup<T>> _unfilteredOptionGroups = [];
106107

107108
_NestedFilterableSelectionOptions(
108109
List<OptionGroup<T>> options, Map<T, List<OptionGroup<T>>> children)
@@ -113,7 +114,7 @@ class _NestedFilterableSelectionOptions<T extends String>
113114
@override
114115
DisposableFuture<bool> filter(Object? filterQuery, {int? limit = -1}) {
115116
var filteredResults = <OptionGroup<T>>[];
116-
for (var optionGroup in _unfilteredOptionGroups!) {
117+
for (var optionGroup in _unfilteredOptionGroups) {
117118
var resultOptionGroup = _filterGroup(filterQuery as String?, optionGroup);
118119
if (resultOptionGroup != null) {
119120
filteredResults.add(resultOptionGroup);
@@ -139,7 +140,7 @@ class _NestedFilterableSelectionOptions<T extends String>
139140
if (currentQuery != null) {
140141
filter(currentQuery, limit: currentLimit);
141142
} else {
142-
super.optionGroups = _unfilteredOptionGroups!;
143+
super.optionGroups = _unfilteredOptionGroups;
143144
}
144145
}
145146
}

0 commit comments

Comments
 (0)