From 57ab0bc1584318fcb281e572adb25c05a396371b Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 28 Apr 2022 09:23:02 -0700 Subject: [PATCH] GridView child_aspect_ratio --- client/lib/controls/grid_view.dart | 5 +++-- sdk/python/flet/grid_view.py | 12 ++++++++++++ sdk/python/playground/icons-browser.py | 9 +++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/client/lib/controls/grid_view.dart b/client/lib/controls/grid_view.dart index f0a291a1b..d57347930 100644 --- a/client/lib/controls/grid_view.dart +++ b/client/lib/controls/grid_view.dart @@ -30,6 +30,7 @@ class GridViewControl extends StatelessWidget { final spacing = control.attrDouble("spacing", 10)!; final runSpacing = control.attrDouble("runSpacing", 10)!; final padding = parseEdgeInsets(control, "padding"); + final childAspectRatio = control.attrDouble("childAspectRatio", 1)!; List visibleControls = children.where((c) => c.isVisible).toList(); @@ -38,12 +39,12 @@ class GridViewControl extends StatelessWidget { crossAxisCount: runsCount, mainAxisSpacing: spacing, crossAxisSpacing: runSpacing, - childAspectRatio: 1) + childAspectRatio: childAspectRatio) : SliverGridDelegateWithMaxCrossAxisExtent( maxCrossAxisExtent: maxExtent, mainAxisSpacing: spacing, crossAxisSpacing: runSpacing, - childAspectRatio: 1); + childAspectRatio: childAspectRatio); return constrainedControl( GridView.builder( diff --git a/sdk/python/flet/grid_view.py b/sdk/python/flet/grid_view.py index eaef40d8a..cbf171abf 100644 --- a/sdk/python/flet/grid_view.py +++ b/sdk/python/flet/grid_view.py @@ -30,6 +30,7 @@ def __init__( max_extent: int = None, spacing: OptionalNumber = None, run_spacing: OptionalNumber = None, + child_aspect_ratio: OptionalNumber = None, padding: PaddingValue = None, ): ConstrainedControl.__init__( @@ -51,6 +52,7 @@ def __init__( self.max_extent = max_extent self.spacing = spacing self.run_spacing = run_spacing + self.child_aspect_ratio = child_aspect_ratio self.padding = padding def _get_control_name(self): @@ -109,6 +111,16 @@ def run_spacing(self): def run_spacing(self, value: OptionalNumber): self._set_attr("runSpacing", value) + # child_aspect_ratio + @property + def child_aspect_ratio(self): + return self._get_attr("childAspectRatio") + + @child_aspect_ratio.setter + @beartype + def child_aspect_ratio(self, value: OptionalNumber): + self._set_attr("childAspectRatio", value) + # padding @property def padding(self): diff --git a/sdk/python/playground/icons-browser.py b/sdk/python/playground/icons-browser.py index bc0099995..cb6c9ee00 100644 --- a/sdk/python/playground/icons-browser.py +++ b/sdk/python/playground/icons-browser.py @@ -46,7 +46,12 @@ def main(page: Page): # search_results = ListView(expand=1, wrap=True, scroll="always") # search_results = ListView(expand=1, spacing=2) search_results = GridView( - expand=1, runs_count=10, max_extent=100, spacing=5, run_spacing=5 + expand=1, + runs_count=10, + max_extent=150, + spacing=5, + run_spacing=5, + child_aspect_ratio=2, ) def display_icons(search_term: str): @@ -101,4 +106,4 @@ def search_click(e): ) -flet.app(name="test1", port=8550, target=main, view=flet.FLET_APP) +flet.app(name="test1", port=8550, target=main, view=flet.WEB_BROWSER)