Skip to content

Commit

Permalink
ListView.reverse and GridView.reverse props (#2335)
Browse files Browse the repository at this point in the history
* ScrollableControl.reverse

* ListView.reverse

* GridView.reverse
  • Loading branch information
ndonkoHenri authored Jan 8, 2024
1 parent 31ef1bf commit 43676d1
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package/lib/src/controls/grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class _GridViewControlState extends State<GridViewControl> {
final runSpacing = widget.control.attrDouble("runSpacing", 10)!;
final padding = parseEdgeInsets(widget.control, "padding");
final childAspectRatio = widget.control.attrDouble("childAspectRatio", 1)!;
final reverse = widget.control.attrBool("reverse", false)!;

List<Control> visibleControls =
widget.children.where((c) => c.isVisible).toList();
Expand Down Expand Up @@ -84,6 +85,7 @@ class _GridViewControlState extends State<GridViewControl> {
Widget child = GridView.builder(
scrollDirection: horizontal ? Axis.horizontal : Axis.vertical,
controller: _controller,
reverse: reverse,
shrinkWrap: shrinkWrap,
padding: padding,
gridDelegate: gridDelegate,
Expand Down
3 changes: 3 additions & 0 deletions package/lib/src/controls/list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class _ListViewControlState extends State<ListViewControl> {
final firstItemPrototype =
widget.control.attrBool("firstItemPrototype", false)!;
final padding = parseEdgeInsets(widget.control, "padding");
final reverse = widget.control.attrBool("reverse", false)!;

List<Control> visibleControls =
widget.children.where((c) => c.isVisible).toList();
Expand All @@ -72,6 +73,7 @@ class _ListViewControlState extends State<ListViewControl> {
Widget child = spacing > 0
? ListView.separated(
controller: _controller,
reverse: reverse,
scrollDirection: horizontal ? Axis.horizontal : Axis.vertical,
shrinkWrap: shrinkWrap,
padding: padding,
Expand All @@ -94,6 +96,7 @@ class _ListViewControlState extends State<ListViewControl> {
)
: ListView.builder(
controller: _controller,
reverse: reverse,
scrollDirection: horizontal ? Axis.horizontal : Axis.vertical,
shrinkWrap: shrinkWrap,
padding: padding,
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/grid_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(
# ScrollableControl specific
#
auto_scroll: Optional[bool] = None,
reverse: Optional[bool] = None,
on_scroll_interval: OptionalNumber = None,
on_scroll: Any = None,
#
Expand Down Expand Up @@ -138,6 +139,7 @@ def __init__(
ScrollableControl.__init__(
self,
auto_scroll=auto_scroll,
reverse=reverse,
on_scroll_interval=on_scroll_interval,
on_scroll=on_scroll,
)
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(
# ScrollableControl specific
#
auto_scroll: Optional[bool] = None,
reverse: Optional[bool] = None,
on_scroll_interval: OptionalNumber = None,
on_scroll: Any = None,
#
Expand Down Expand Up @@ -129,6 +130,7 @@ def __init__(
ScrollableControl.__init__(
self,
auto_scroll=auto_scroll,
reverse=reverse,
on_scroll_interval=on_scroll_interval,
on_scroll=on_scroll,
)
Expand Down
15 changes: 13 additions & 2 deletions sdk/python/packages/flet-core/src/flet_core/scrollable_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(
self,
scroll: Optional[ScrollMode] = None,
auto_scroll: Optional[bool] = None,
reverse: Optional[bool] = None,
on_scroll_interval: OptionalNumber = None,
on_scroll: Any = None,
):
Expand All @@ -26,6 +27,7 @@ def convert_on_scroll_event_data(e):

self.scroll = scroll
self.auto_scroll = auto_scroll
self.reverse = reverse
self.on_scroll_interval = on_scroll_interval
self.on_scroll = on_scroll

Expand Down Expand Up @@ -95,13 +97,22 @@ def __set_scroll(self, value: Optional[ScrollModeString]):

# auto_scroll
@property
def auto_scroll(self) -> Optional[bool]:
return self._get_attr("autoScroll")
def auto_scroll(self) -> Optional[str]:
return self._get_attr("autoScroll", data_type="bool", def_value=False)

@auto_scroll.setter
def auto_scroll(self, value: Optional[bool]):
self._set_attr("autoScroll", value)

# reverse
@property
def reverse(self) -> Optional[bool]:
return self._get_attr("reverse", data_type="bool", def_value=False)

@reverse.setter
def reverse(self, value: Optional[bool]):
self._set_attr("reverse", value)

# on_scroll_interval
@property
def on_scroll_interval(self) -> OptionalNumber:
Expand Down

0 comments on commit 43676d1

Please sign in to comment.