Skip to content

Commit b841a6e

Browse files
Row, Column and ListView spacing and scrolling improvements (#13)
1 parent f6ed32d commit b841a6e

File tree

9 files changed

+120
-13
lines changed

9 files changed

+120
-13
lines changed

client/lib/controls/column.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ColumnControl extends StatelessWidget {
3333
m.name.toLowerCase() ==
3434
control.attrString("scroll", "")!.toLowerCase(),
3535
orElse: () => ScrollMode.none);
36+
final autoScroll = control.attrBool("autoScroll", false)!;
3637
bool disabled = control.isDisabled || parentDisabled;
3738

3839
List<Widget> controls = [];
@@ -79,6 +80,7 @@ class ColumnControl extends StatelessWidget {
7980
child: widget,
8081
scrollDirection: wrap ? Axis.horizontal : Axis.vertical,
8182
scrollMode: scrollMode,
83+
autoScroll: autoScroll,
8284
)
8385
: widget,
8486
parent,

client/lib/controls/list_view.dart

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class ListViewControl extends StatelessWidget {
2020

2121
final ScrollController _controller = ScrollController();
2222

23-
// This is what you're looking for!
2423
void _scrollDown() {
2524
_controller.animateTo(
2625
_controller.position.maxScrollExtent,
@@ -38,6 +37,9 @@ class ListViewControl extends StatelessWidget {
3837
final horizontal = control.attrBool("horizontal", false)!;
3938
final autoScroll = control.attrBool("autoScroll", false)!;
4039
final spacing = control.attrDouble("spacing", 0)!;
40+
final dividerThickness = control.attrDouble("dividerThickness", 0)!;
41+
final itemExtent = control.attrDouble("itemExtent");
42+
final firstItemPrototype = control.attrBool("firstItemPrototype", false)!;
4143
final padding = parseEdgeInsets(control, "padding");
4244

4345
List<Control> visibleControls = children.where((c) => c.isVisible).toList();
@@ -60,19 +62,28 @@ class ListViewControl extends StatelessWidget {
6062
control, visibleControls[index].id, disabled);
6163
},
6264
separatorBuilder: (context, index) {
63-
return Divider(height: spacing);
65+
return horizontal
66+
? dividerThickness == 0
67+
? SizedBox(width: spacing)
68+
: VerticalDivider(
69+
width: spacing, thickness: dividerThickness)
70+
: dividerThickness == 0
71+
? SizedBox(height: spacing)
72+
: Divider(
73+
height: spacing, thickness: dividerThickness);
6474
},
6575
)
6676
: ListView.builder(
6777
controller: _controller,
6878
scrollDirection: horizontal ? Axis.horizontal : Axis.vertical,
6979
padding: padding,
7080
itemCount: children.length,
81+
itemExtent: itemExtent,
7182
itemBuilder: (context, index) {
7283
return createControl(
7384
control, visibleControls[index].id, disabled);
7485
},
75-
prototypeItem: children.isNotEmpty
86+
prototypeItem: firstItemPrototype && children.isNotEmpty
7687
? createControl(control, visibleControls[0].id, disabled)
7788
: null,
7889
),

client/lib/controls/page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class PageControl extends StatelessWidget {
4242
control.attrString("scroll", "")!.toLowerCase(),
4343
orElse: () => ScrollMode.none);
4444

45-
debugPrint("scrollMode: $scrollMode");
45+
final autoScroll = control.attrBool("autoScroll", false)!;
4646

4747
Control? offstage;
4848
Control? appBar;
@@ -168,6 +168,7 @@ class PageControl extends StatelessWidget {
168168
child: column,
169169
scrollDirection: Axis.vertical,
170170
scrollMode: scrollMode,
171+
autoScroll: autoScroll,
171172
)
172173
: column)),
173174
...offstageWidgets,

client/lib/controls/row.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class RowControl extends StatelessWidget {
3333
m.name.toLowerCase() ==
3434
control.attrString("scroll", "")!.toLowerCase(),
3535
orElse: () => ScrollMode.none);
36+
final autoScroll = control.attrBool("autoScroll", false)!;
3637
bool disabled = control.isDisabled || parentDisabled;
3738

3839
List<Widget> controls = [];
@@ -75,18 +76,22 @@ class RowControl extends StatelessWidget {
7576
children: controls,
7677
),
7778
wrap: wrap,
78-
scrollMode: scrollMode),
79+
scrollMode: scrollMode,
80+
autoScroll: autoScroll),
7981
parent,
8082
control);
8183
}
8284

8385
Widget wrapAutoScroll(Widget child,
84-
{required bool wrap, required ScrollMode scrollMode}) {
86+
{required bool wrap,
87+
required ScrollMode scrollMode,
88+
required bool autoScroll}) {
8589
return scrollMode != ScrollMode.none
8690
? ScrollableControl(
8791
child: child,
8892
scrollDirection: wrap ? Axis.vertical : Axis.horizontal,
8993
scrollMode: scrollMode,
94+
autoScroll: autoScroll,
9095
)
9196
: child;
9297
}

client/lib/controls/scrollable_control.dart

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ class ScrollableControl extends StatefulWidget {
99
final Widget child;
1010
final Axis scrollDirection;
1111
final ScrollMode scrollMode;
12+
final bool autoScroll;
1213

1314
const ScrollableControl(
1415
{Key? key,
1516
required this.child,
1617
required this.scrollDirection,
17-
required this.scrollMode})
18+
required this.scrollMode,
19+
required this.autoScroll})
1820
: super(key: key);
1921

2022
@override
@@ -24,16 +26,32 @@ class ScrollableControl extends StatefulWidget {
2426
class _ScrollableControlState extends State<ScrollableControl> {
2527
final ScrollController _controller = ScrollController();
2628

29+
void _scrollDown() {
30+
_controller.animateTo(
31+
_controller.position.maxScrollExtent,
32+
duration: const Duration(seconds: 1),
33+
curve: Curves.fastOutSlowIn,
34+
);
35+
}
36+
2737
@override
2838
Widget build(BuildContext context) {
29-
bool isAlwaysShown = widget.scrollMode == ScrollMode.always ||
30-
(widget.scrollMode == ScrollMode.adaptive &&
31-
!kIsWeb &&
32-
!Platform.isIOS &&
33-
!Platform.isAndroid);
39+
bool? thumbVisibility = widget.scrollMode == ScrollMode.always ||
40+
(widget.scrollMode == ScrollMode.adaptive &&
41+
!kIsWeb &&
42+
!Platform.isIOS &&
43+
!Platform.isAndroid)
44+
? true
45+
: null;
46+
47+
if (widget.autoScroll) {
48+
WidgetsBinding.instance.addPostFrameCallback((_) {
49+
_scrollDown();
50+
});
51+
}
3452

3553
return Scrollbar(
36-
isAlwaysShown: isAlwaysShown,
54+
thumbVisibility: thumbVisibility,
3755
controller: _controller,
3856
child: SingleChildScrollView(
3957
controller: _controller,

sdk/python/flet/column.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(
3535
wrap: bool = None,
3636
run_spacing: OptionalNumber = None,
3737
scroll: ScrollMode = None,
38+
auto_scroll: bool = None,
3839
):
3940
ConstrainedControl.__init__(
4041
self,
@@ -58,6 +59,7 @@ def __init__(
5859
self.run_spacing = run_spacing
5960
self.__scroll = False
6061
self.scroll = scroll
62+
self.auto_scroll = auto_scroll
6163

6264
def _get_control_name(self):
6365
return "column"
@@ -144,6 +146,16 @@ def scroll(self, value: ScrollMode):
144146
value = "none"
145147
self._set_attr("scroll", value)
146148

149+
# auto_scroll
150+
@property
151+
def auto_scroll(self):
152+
return self._get_attr("autoScroll")
153+
154+
@auto_scroll.setter
155+
@beartype
156+
def auto_scroll(self, value: Optional[bool]):
157+
self._set_attr("autoScroll", value)
158+
147159
# controls
148160
@property
149161
def controls(self):

sdk/python/flet/list_view.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ def __init__(
2525
#
2626
horizontal: bool = None,
2727
spacing: OptionalNumber = None,
28+
item_extent: OptionalNumber = None,
29+
first_item_prototype: bool = None,
30+
divider_thickness: OptionalNumber = None,
2831
padding: PaddingValue = None,
2932
auto_scroll: bool = None,
3033
):
@@ -44,6 +47,9 @@ def __init__(
4447
self.controls = controls
4548
self.horizontal = horizontal
4649
self.spacing = spacing
50+
self.divider_thickness = divider_thickness
51+
self.item_extent = item_extent
52+
self.first_item_prototype = first_item_prototype
4753
self.padding = padding
4854
self.auto_scroll = auto_scroll
4955

@@ -77,6 +83,36 @@ def spacing(self):
7783
def spacing(self, value: OptionalNumber):
7884
self._set_attr("spacing", value)
7985

86+
# divider_thickness
87+
@property
88+
def divider_thickness(self):
89+
return self._get_attr("dividerThickness")
90+
91+
@divider_thickness.setter
92+
@beartype
93+
def divider_thickness(self, value: OptionalNumber):
94+
self._set_attr("dividerThickness", value)
95+
96+
# item_extent
97+
@property
98+
def item_extent(self):
99+
return self._get_attr("itemExtent")
100+
101+
@item_extent.setter
102+
@beartype
103+
def item_extent(self, value: OptionalNumber):
104+
self._set_attr("itemExtent", value)
105+
106+
# first_item_prototype
107+
@property
108+
def first_item_prototype(self):
109+
return self._get_attr("firstItemPrototype")
110+
111+
@first_item_prototype.setter
112+
@beartype
113+
def first_item_prototype(self, value: Optional[bool]):
114+
self._set_attr("firstItemPrototype", value)
115+
80116
# padding
81117
@property
82118
def padding(self):

sdk/python/flet/page.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,16 @@ def scroll(self, value: ScrollMode):
445445
value = "none"
446446
self._set_attr("scroll", value)
447447

448+
# auto_scroll
449+
@property
450+
def auto_scroll(self):
451+
return self._get_attr("autoScroll")
452+
453+
@auto_scroll.setter
454+
@beartype
455+
def auto_scroll(self, value: Optional[bool]):
456+
self._set_attr("autoScroll", value)
457+
448458
# window_width
449459
@property
450460
def window_width(self):

sdk/python/flet/row.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(
3535
wrap: bool = None,
3636
run_spacing: OptionalNumber = None,
3737
scroll: ScrollMode = None,
38+
auto_scroll: bool = None,
3839
):
3940
ConstrainedControl.__init__(
4041
self,
@@ -58,6 +59,7 @@ def __init__(
5859
self.run_spacing = run_spacing
5960
self.__scroll = False
6061
self.scroll = scroll
62+
self.auto_scroll = auto_scroll
6163

6264
def _get_control_name(self):
6365
return "row"
@@ -144,6 +146,16 @@ def scroll(self, value: ScrollMode):
144146
value = "none"
145147
self._set_attr("scroll", value)
146148

149+
# auto_scroll
150+
@property
151+
def auto_scroll(self):
152+
return self._get_attr("autoScroll")
153+
154+
@auto_scroll.setter
155+
@beartype
156+
def auto_scroll(self, value: Optional[bool]):
157+
self._set_attr("autoScroll", value)
158+
147159
# controls
148160
@property
149161
def controls(self):

0 commit comments

Comments
 (0)