Skip to content

add offsetRight to add padding to rtl #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions lib/src/tree_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class TreeNode extends StatefulWidget {
final bool showActions;
final bool contentTappable;
final double offsetLeft;
final double offsetRight;
final int? maxLines;

final Function(TreeNodeData node) onTap;
Expand Down Expand Up @@ -52,13 +53,15 @@ class TreeNode extends StatefulWidget {
required this.onAppend,
required this.onRemove,
required this.onCollapse,
required this.offsetRight,
}) : super(key: key);

@override
_TreeNodeState createState() => _TreeNodeState();
}

class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin {
class _TreeNodeState extends State<TreeNode>
with SingleTickerProviderStateMixin {
bool _isExpanded = false;
bool _isChecked = false;
bool _showLoading = false;
Expand All @@ -77,6 +80,7 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
lazy: widget.lazy,
load: widget.load,
offsetLeft: widget.offsetLeft,
offsetRight: widget.offsetRight,
maxLines: widget.maxLines,
showCheckBox: widget.showCheckBox,
showActions: widget.showActions,
Expand Down Expand Up @@ -116,25 +120,30 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
Widget build(BuildContext context) {
if (widget.parentState != null) _isChecked = widget.data.checked;

bool hasData = widget.data.children.isNotEmpty || (widget.lazy && !_isExpanded);
bool hasData =
widget.data.children.isNotEmpty || (widget.lazy && !_isExpanded);

return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
InkWell(
splashColor: widget.contentTappable ? null : Colors.transparent,
highlightColor: widget.contentTappable ? null : Colors.transparent,
mouseCursor: widget.contentTappable ? SystemMouseCursors.click : MouseCursor.defer,
onTap: widget.contentTappable ? () {
if (hasData) {
widget.onTap(widget.data);
toggleExpansion();
} else {
_isChecked = !_isChecked;
widget.onCheck(_isChecked, widget.data);
setState(() {});
}
} : (){},
mouseCursor: widget.contentTappable
? SystemMouseCursors.click
: MouseCursor.defer,
onTap: widget.contentTappable
? () {
if (hasData) {
widget.onTap(widget.data);
toggleExpansion();
} else {
_isChecked = !_isChecked;
widget.onCheck(_isChecked, widget.data);
setState(() {});
}
}
: () {},
child: Container(
margin: const EdgeInsets.only(bottom: 2.0),
padding: const EdgeInsets.only(right: 12.0),
Expand All @@ -145,10 +154,12 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
child: IconButton(
iconSize: 16,
icon: hasData ? widget.icon : Container(),
onPressed: hasData ? () {
widget.onTap(widget.data);
toggleExpansion();
} : null,
onPressed: hasData
? () {
widget.onTap(widget.data);
toggleExpansion();
}
: null,
),
turns: _turnsTween.animate(_rotationController),
),
Expand Down Expand Up @@ -198,7 +209,8 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
widget.remove(widget.data);
widget.onRemove(widget.data, widget.parent);
},
child: const Text('Remove', style: TextStyle(fontSize: 12.0)),
child:
const Text('Remove', style: TextStyle(fontSize: 12.0)),
),
if (widget.data.customActions?.isNotEmpty == true)
...widget.data.customActions!,
Expand All @@ -209,7 +221,8 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
SizeTransition(
sizeFactor: _rotationController,
child: Padding(
padding: EdgeInsets.only(left: widget.offsetLeft),
padding: EdgeInsets.only(
left: widget.offsetLeft, right: widget.offsetRight),
child: Column(children: _geneTreeNodes(widget.data.children)),
),
)
Expand Down
17 changes: 10 additions & 7 deletions lib/src/tree_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TreeView extends StatefulWidget {
final bool lazy;
final Widget icon;
final double offsetLeft;
final double offsetRight;
final int? maxLines;
final bool showFilter;
final String filterPlaceholder;
Expand Down Expand Up @@ -46,6 +47,7 @@ class TreeView extends StatefulWidget {
this.load,
this.lazy = false,
this.offsetLeft = 24.0,
this.offsetRight = 0.0,
this.maxLines,
this.showFilter = false,
this.filterPlaceholder = 'Search',
Expand Down Expand Up @@ -74,7 +76,8 @@ class _TreeViewState extends State<TreeView> {
tempNode.children = _filter(val, tempNode.children);
}

if (tempNode.title.contains(RegExp(val, caseSensitive: false)) || tempNode.children.isNotEmpty) {
if (tempNode.title.contains(RegExp(val, caseSensitive: false)) ||
tempNode.children.isNotEmpty) {
tempNodes.add(tempNode);
}
}
Expand All @@ -83,7 +86,7 @@ class _TreeViewState extends State<TreeView> {
}

void _onChange(String val) {
_renderList = widget.data;
_renderList = widget.data;

if (val.isNotEmpty) {
_renderList = _filter(val, _renderList);
Expand Down Expand Up @@ -150,11 +153,10 @@ class _TreeViewState extends State<TreeView> {
bottom: 12.0,
),
child: TextField(
onChanged: _onChange,
decoration: InputDecoration(
labelText: widget.filterPlaceholder,
)
),
onChanged: _onChange,
decoration: InputDecoration(
labelText: widget.filterPlaceholder,
)),
),
...List.generate(
_renderList.length,
Expand All @@ -169,6 +171,7 @@ class _TreeViewState extends State<TreeView> {
icon: widget.icon,
lazy: widget.lazy,
offsetLeft: widget.offsetLeft,
offsetRight: widget.offsetRight,
maxLines: widget.maxLines,
showCheckBox: widget.showCheckBox,
showActions: widget.showActions,
Expand Down