Skip to content

Commit

Permalink
GridView child_aspect_ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
FeodorFitsner committed Apr 28, 2022
1 parent 94afb26 commit 57ab0bc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions client/lib/controls/grid_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Control> visibleControls = children.where((c) => c.isVisible).toList();

Expand All @@ -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(
Expand Down
12 changes: 12 additions & 0 deletions sdk/python/flet/grid_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__(
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
9 changes: 7 additions & 2 deletions sdk/python/playground/icons-browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

0 comments on commit 57ab0bc

Please sign in to comment.