Null check operator used on a null value
when i update to the 1.0.1+1
1 need physics: BouncingScrollPhysics()
else throw error
TreeView(
key: _treeKey,
controller: _treeViewController,
allowParentSelect: true,
supportParentDoubleTap: false,
physics: BouncingScrollPhysics(),
onExpansionChanged: _expandNodeHandler,
onNodeTap: _onNodeTap,
onNodeDoubleTap: (key) {},
nodeBuilder: builder,
theme: treeViewTheme)
2 when click node ,throw error
Node getNode(String key, {Node? parent}) {
Node? _found;
List<Node> _children = parent == null ? this.children : parent.children;
Iterator iter = _children.iterator;
while (iter.moveNext()) {
Node child = iter.current;
if (child.key == key) {
_found = child;
break;
} else {
if (child.isParent) {
_found = this.getNode(key, parent: child);
if (_found != null) {
break;
}
}
}
}
return _found!;
}
look the code,find that when can't find a node by key , return _found!;
will throw error --- Null check operator used on a null value
Fix
Node? getNode(String key, {Node? parent}) {
Node? _found;
List<Node> _children = parent == null ? this.children : parent.children;
Iterator iter = _children.iterator;
while (iter.moveNext()) {
Node child = iter.current;
if (child.key == key) {
_found = child;
break;
} else {
if (child.isParent) {
_found = this.getNode(key, parent: child);
if (_found != null) {
break;
}
}
}
}
return _found;
}
and some where use getNode()
Node _node = _this.getNode(k);
fix to
Node _node = _this.getNode(k)!;
Comments (7)
-
reporter -
reporter
-
- changed status to resolved
- Fixes issue
#34: Null check operator used on a null value - Fixes issue
#35: Node Data not being written when TreeViewController is converted back to a Map Create issue
→ <<cset 7a05200b231a>>
-
@xsm123 Thanks for the suggestion on the null check. I made that change and published them. I’m not sure what’s happening with the physics property in your app. The property is optional. Let me know if you continue to have issues.
-
I am still getting the same error if I don’t include ‘physics’. I traced it down to the following line
Getting past that, I passed in a
ScrollPhysics
object and, using the example on the front page, it returns an empty list. Using v 1.0.3+1 and flutter stable 2.0.3.
-
@Mac Spinks I was able to reproduce it. I just fixed the issue and published the new version. Hopefully that addresses all null safety related issues.
-
Kevin, thank you for the response. That fixed the issue. Ignore my mention of the other issue. That was my fault
- Log in to comment
need
physics: BouncingScrollPhysics()
else throw errorIt can't be reproduced. Maybe it's my environment fault