From 54ea0440c5df6778bf2461968115a98d51513fc9 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Wed, 19 Jun 2024 16:32:05 -0700 Subject: [PATCH] Fix `parseFloatingActionButtonLocation()` to work on desktop (#3496) * Fix parseFloatingActionButtonLocation to work on desktop Fix #3485 * Update changelog * make fabLocations const Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --------- Co-authored-by: TheEthicalBoy <98978078+ndonkoHenri@users.noreply.github.com> Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com> --- CHANGELOG.md | 1 + packages/flet/CHANGELOG.md | 1 + packages/flet/lib/src/utils/buttons.dart | 47 +++++++++++------------- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 108ba9795..2f632e6d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ # 0.23.1 +* FIX: Fix parseFloatingActionButtonLocation() to work on desktop ([#3496](https://github.com/flet-dev/flet/issues/3496)) * FIX: Flet 0.23 crashes on Ubuntu 22.04 ([#3495](https://github.com/flet-dev/flet/issues/3495)) * FIX: View.floating_action_button_location: conditionally use _set_attr. * FIX: Import `ParamSpec` from `typing` for Python >3.10. diff --git a/packages/flet/CHANGELOG.md b/packages/flet/CHANGELOG.md index b4ee11e7c..bcf0a83da 100644 --- a/packages/flet/CHANGELOG.md +++ b/packages/flet/CHANGELOG.md @@ -1,5 +1,6 @@ # 0.23.1 +* FIX: Fix parseFloatingActionButtonLocation() to work on desktop ([#3496](https://github.com/flet-dev/flet/issues/3496)) * FIX: Flet 0.23 crashes on Ubuntu 22.04 ([#3495](https://github.com/flet-dev/flet/issues/3495)) * FIX: View.floating_action_button_location: conditionally use _set_attr. * FIX: Import `ParamSpec` from `typing` for Python >3.10. diff --git a/packages/flet/lib/src/utils/buttons.dart b/packages/flet/lib/src/utils/buttons.dart index 6c208a165..09eab05b1 100644 --- a/packages/flet/lib/src/utils/buttons.dart +++ b/packages/flet/lib/src/utils/buttons.dart @@ -83,26 +83,26 @@ ButtonStyle? buttonStyleFromJSON(ThemeData theme, Map? json, FloatingActionButtonLocation parseFloatingActionButtonLocation( Control control, String propName, FloatingActionButtonLocation defValue) { - List fabLocations = [ - FloatingActionButtonLocation.centerDocked, - FloatingActionButtonLocation.centerFloat, - FloatingActionButtonLocation.centerTop, - FloatingActionButtonLocation.endContained, - FloatingActionButtonLocation.endDocked, - FloatingActionButtonLocation.endFloat, - FloatingActionButtonLocation.endTop, - FloatingActionButtonLocation.miniCenterDocked, - FloatingActionButtonLocation.miniCenterFloat, - FloatingActionButtonLocation.miniCenterTop, - FloatingActionButtonLocation.miniEndFloat, - FloatingActionButtonLocation.miniEndTop, - FloatingActionButtonLocation.miniStartDocked, - FloatingActionButtonLocation.miniStartFloat, - FloatingActionButtonLocation.miniStartTop, - FloatingActionButtonLocation.startDocked, - FloatingActionButtonLocation.startFloat, - FloatingActionButtonLocation.startTop - ]; + const Map fabLocations = { + "centerdocked": FloatingActionButtonLocation.centerDocked, + "centerfloat": FloatingActionButtonLocation.centerFloat, + "centertop": FloatingActionButtonLocation.centerTop, + "endcontained": FloatingActionButtonLocation.endContained, + "enddocked": FloatingActionButtonLocation.endDocked, + "endfloat": FloatingActionButtonLocation.endFloat, + "endtop": FloatingActionButtonLocation.endTop, + "minicenterdocked": FloatingActionButtonLocation.miniCenterDocked, + "minicenterfloat": FloatingActionButtonLocation.miniCenterFloat, + "minicentertop": FloatingActionButtonLocation.miniCenterTop, + "miniendfloat": FloatingActionButtonLocation.miniEndFloat, + "miniendtop": FloatingActionButtonLocation.miniEndTop, + "ministartdocked": FloatingActionButtonLocation.miniStartDocked, + "ministartfloat": FloatingActionButtonLocation.miniStartFloat, + "ministarttop": FloatingActionButtonLocation.miniStartTop, + "startdocked": FloatingActionButtonLocation.startDocked, + "startfloat": FloatingActionButtonLocation.startFloat, + "starttop": FloatingActionButtonLocation.startTop + }; try { OffsetDetails? fabLocationOffsetDetails = parseOffset(control, propName); @@ -113,11 +113,8 @@ FloatingActionButtonLocation parseFloatingActionButtonLocation( return defValue; } } catch (e) { - return fabLocations.firstWhere( - (l) => - l.toString().split('.').last.toLowerCase() == - control.attrString(propName, "")!.toLowerCase(), - orElse: () => defValue); + var key = control.attrString(propName, "")!.toLowerCase(); + return fabLocations.containsKey(key) ? fabLocations[key]! : defValue; } }