Skip to content

Commit

Permalink
Fix parseFloatingActionButtonLocation() to work on desktop (#3496)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Jun 19, 2024
1 parent b0da0e7 commit f1c6c32
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 f1c6c32

Please sign in to comment.