Skip to content

Commit

Permalink
Fix parseFloatingActionButtonLocation() to work on desktop (flet-de…
Browse files Browse the repository at this point in the history
…v#3496)

* Fix parseFloatingActionButtonLocation to work on desktop

Fix flet-dev#3485

* Update changelog

* make fabLocations const

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

---------

Co-authored-by: TheEthicalBoy <[email protected]>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored and zrr1999 committed Jul 17, 2024
1 parent b653fd2 commit 54ea044
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 25 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/flet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
47 changes: 22 additions & 25 deletions packages/flet/lib/src/utils/buttons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,26 @@ ButtonStyle? buttonStyleFromJSON(ThemeData theme, Map<String, dynamic>? json,

FloatingActionButtonLocation parseFloatingActionButtonLocation(
Control control, String propName, FloatingActionButtonLocation defValue) {
List<FloatingActionButtonLocation> 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<String, FloatingActionButtonLocation> 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);
Expand All @@ -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;
}
}

Expand Down

0 comments on commit 54ea044

Please sign in to comment.