Skip to content

Commit

Permalink
feat: Mark MenuFlyoutItem as disabled when .onPressed is null (F…
Browse files Browse the repository at this point in the history
…ixes #1074)
  • Loading branch information
bdlukaa committed Jun 23, 2024
1 parent eec6560 commit 00c3b19
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* feat: Add `NumberBox.textInputAction` and `NumberBox.onEditingComplete` ([#1063](https://github.com/bdlukaa/fluent_ui/pull/1063))
* feat: Add `Tab.color`, `Tab.selectedColor` and `Tab.outlineColor` to TabView ([#1068](https://github.com/bdlukaa/fluent_ui/pull/1068))
* feat: Added `NavigationView.onItemPressed` callback, called when the item is on tap ([#1067](https://github.com/bdlukaa/fluent_ui/pull/1067))
* **BREAKING** feat: Removed `ButtonState`, `ButtonStates` and their related classes. Use `WidgetStateProperty`, `WidgetState` instead.
* fix: Mark `MenuFlyoutItem` as disabled when `.onPressed` is `null` ([#1074](https://github.com/bdlukaa/fluent_ui/issues/1074))
* **BREAKING** feat: Removed `ButtonState`, `ButtonStates` and their related classes. Use `WidgetStateProperty`, `WidgetState` instead. ([#1075](https://github.com/bdlukaa/fluent_ui/issues/1075))
Before:

```dart
Expand Down
2 changes: 1 addition & 1 deletion example/lib/screens/popups/flyout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ FlyoutTarget(
),
MenuFlyoutItem(
text: const Text('Select'),
onPressed: Flyout.of(context).close,
onPressed: null,
),
const MenuFlyoutSeparator(),
MenuFlyoutSubItem(
Expand Down
9 changes: 7 additions & 2 deletions lib/src/controls/flyouts/content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ class FlyoutListTile extends StatelessWidget {

final bool showSelectedIndicator;

bool get isEnabled => onPressed != null;

@override
Widget build(BuildContext context) {
assert(debugCheckHasFluentTheme(context));
Expand All @@ -168,6 +170,9 @@ class FlyoutListTile extends StatelessWidget {
states = {WidgetState.hovered};
}

final foregroundColor =
ButtonThemeData.buttonForegroundColor(context, states);

Widget content = Stack(children: [
Container(
decoration: BoxDecoration(
Expand All @@ -189,7 +194,7 @@ class FlyoutListTile extends StatelessWidget {
Padding(
padding: const EdgeInsetsDirectional.only(end: 10.0),
child: IconTheme.merge(
data: const IconThemeData(size: 16.0),
data: IconThemeData(size: 16.0, color: foregroundColor),
child: icon!,
),
),
Expand All @@ -203,7 +208,7 @@ class FlyoutListTile extends StatelessWidget {
style: TextStyle(
fontSize: 14.0,
letterSpacing: -0.15,
color: theme.inactiveColor,
color: foregroundColor,
),
child: text,
),
Expand Down
10 changes: 6 additions & 4 deletions lib/src/controls/flyouts/menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -280,10 +280,12 @@ class MenuFlyoutItem extends MenuFlyoutItemBase {
data: const IconThemeData(size: 12.0),
child: trailing ?? const SizedBox.shrink(),
),
onPressed: () {
Navigator.of(context).maybePop();
onPressed?.call();
},
onPressed: onPressed == null
? null
: () {
Navigator.of(context).maybePop();
onPressed?.call();
},
),
);
}
Expand Down

0 comments on commit 00c3b19

Please sign in to comment.