Skip to content

Commit 59cb74b

Browse files
author
mohamedfaroouk
committed
add offsetRight to add padding to rtl
1 parent c207932 commit 59cb74b

File tree

2 files changed

+42
-26
lines changed

2 files changed

+42
-26
lines changed

lib/src/tree_node.dart

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class TreeNode extends StatefulWidget {
1313
final bool showActions;
1414
final bool contentTappable;
1515
final double offsetLeft;
16+
final double offsetRight;
1617
final int? maxLines;
1718

1819
final Function(TreeNodeData node) onTap;
@@ -52,13 +53,15 @@ class TreeNode extends StatefulWidget {
5253
required this.onAppend,
5354
required this.onRemove,
5455
required this.onCollapse,
56+
required this.offsetRight,
5557
}) : super(key: key);
5658

5759
@override
5860
_TreeNodeState createState() => _TreeNodeState();
5961
}
6062

61-
class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin {
63+
class _TreeNodeState extends State<TreeNode>
64+
with SingleTickerProviderStateMixin {
6265
bool _isExpanded = false;
6366
bool _isChecked = false;
6467
bool _showLoading = false;
@@ -77,6 +80,7 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
7780
lazy: widget.lazy,
7881
load: widget.load,
7982
offsetLeft: widget.offsetLeft,
83+
offsetRight: widget.offsetRight,
8084
maxLines: widget.maxLines,
8185
showCheckBox: widget.showCheckBox,
8286
showActions: widget.showActions,
@@ -116,25 +120,30 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
116120
Widget build(BuildContext context) {
117121
if (widget.parentState != null) _isChecked = widget.data.checked;
118122

119-
bool hasData = widget.data.children.isNotEmpty || (widget.lazy && !_isExpanded);
123+
bool hasData =
124+
widget.data.children.isNotEmpty || (widget.lazy && !_isExpanded);
120125

121126
return Column(
122127
crossAxisAlignment: CrossAxisAlignment.start,
123128
children: <Widget>[
124129
InkWell(
125130
splashColor: widget.contentTappable ? null : Colors.transparent,
126131
highlightColor: widget.contentTappable ? null : Colors.transparent,
127-
mouseCursor: widget.contentTappable ? SystemMouseCursors.click : MouseCursor.defer,
128-
onTap: widget.contentTappable ? () {
129-
if (hasData) {
130-
widget.onTap(widget.data);
131-
toggleExpansion();
132-
} else {
133-
_isChecked = !_isChecked;
134-
widget.onCheck(_isChecked, widget.data);
135-
setState(() {});
136-
}
137-
} : (){},
132+
mouseCursor: widget.contentTappable
133+
? SystemMouseCursors.click
134+
: MouseCursor.defer,
135+
onTap: widget.contentTappable
136+
? () {
137+
if (hasData) {
138+
widget.onTap(widget.data);
139+
toggleExpansion();
140+
} else {
141+
_isChecked = !_isChecked;
142+
widget.onCheck(_isChecked, widget.data);
143+
setState(() {});
144+
}
145+
}
146+
: () {},
138147
child: Container(
139148
margin: const EdgeInsets.only(bottom: 2.0),
140149
padding: const EdgeInsets.only(right: 12.0),
@@ -145,10 +154,12 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
145154
child: IconButton(
146155
iconSize: 16,
147156
icon: hasData ? widget.icon : Container(),
148-
onPressed: hasData ? () {
149-
widget.onTap(widget.data);
150-
toggleExpansion();
151-
} : null,
157+
onPressed: hasData
158+
? () {
159+
widget.onTap(widget.data);
160+
toggleExpansion();
161+
}
162+
: null,
152163
),
153164
turns: _turnsTween.animate(_rotationController),
154165
),
@@ -198,7 +209,8 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
198209
widget.remove(widget.data);
199210
widget.onRemove(widget.data, widget.parent);
200211
},
201-
child: const Text('Remove', style: TextStyle(fontSize: 12.0)),
212+
child:
213+
const Text('Remove', style: TextStyle(fontSize: 12.0)),
202214
),
203215
if (widget.data.customActions?.isNotEmpty == true)
204216
...widget.data.customActions!,
@@ -209,7 +221,8 @@ class _TreeNodeState extends State<TreeNode> with SingleTickerProviderStateMixin
209221
SizeTransition(
210222
sizeFactor: _rotationController,
211223
child: Padding(
212-
padding: EdgeInsets.only(left: widget.offsetLeft),
224+
padding: EdgeInsets.only(
225+
left: widget.offsetLeft, right: widget.offsetRight),
213226
child: Column(children: _geneTreeNodes(widget.data.children)),
214227
),
215228
)

lib/src/tree_view.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class TreeView extends StatefulWidget {
99
final bool lazy;
1010
final Widget icon;
1111
final double offsetLeft;
12+
final double offsetRight;
1213
final int? maxLines;
1314
final bool showFilter;
1415
final String filterPlaceholder;
@@ -46,6 +47,7 @@ class TreeView extends StatefulWidget {
4647
this.load,
4748
this.lazy = false,
4849
this.offsetLeft = 24.0,
50+
this.offsetRight = 0.0,
4951
this.maxLines,
5052
this.showFilter = false,
5153
this.filterPlaceholder = 'Search',
@@ -74,7 +76,8 @@ class _TreeViewState extends State<TreeView> {
7476
tempNode.children = _filter(val, tempNode.children);
7577
}
7678

77-
if (tempNode.title.contains(RegExp(val, caseSensitive: false)) || tempNode.children.isNotEmpty) {
79+
if (tempNode.title.contains(RegExp(val, caseSensitive: false)) ||
80+
tempNode.children.isNotEmpty) {
7881
tempNodes.add(tempNode);
7982
}
8083
}
@@ -83,7 +86,7 @@ class _TreeViewState extends State<TreeView> {
8386
}
8487

8588
void _onChange(String val) {
86-
_renderList = widget.data;
89+
_renderList = widget.data;
8790

8891
if (val.isNotEmpty) {
8992
_renderList = _filter(val, _renderList);
@@ -150,11 +153,10 @@ class _TreeViewState extends State<TreeView> {
150153
bottom: 12.0,
151154
),
152155
child: TextField(
153-
onChanged: _onChange,
154-
decoration: InputDecoration(
155-
labelText: widget.filterPlaceholder,
156-
)
157-
),
156+
onChanged: _onChange,
157+
decoration: InputDecoration(
158+
labelText: widget.filterPlaceholder,
159+
)),
158160
),
159161
...List.generate(
160162
_renderList.length,
@@ -169,6 +171,7 @@ class _TreeViewState extends State<TreeView> {
169171
icon: widget.icon,
170172
lazy: widget.lazy,
171173
offsetLeft: widget.offsetLeft,
174+
offsetRight: widget.offsetRight,
172175
maxLines: widget.maxLines,
173176
showCheckBox: widget.showCheckBox,
174177
showActions: widget.showActions,

0 commit comments

Comments
 (0)