Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [next]

- fix: `MenuFlyout` no longer throws `TypeError` when calling `findRenderObject` on sub-items ([#1337](https://github.com/bdlukaa/fluent_ui/issues/1337))
- feat: Controls now respond to `VisualDensity` from `FluentThemeData` for compact sizing. Use `FluentThemeData(visualDensity: VisualDensity.compact)` to enable compact mode ([#1175](https://github.com/bdlukaa/fluent_ui/issues/1175))
- fix: `NavigationView` no longer throws `BoxConstraints has a negative minimum height` when header and menu button are both absent ([#1334](https://github.com/bdlukaa/fluent_ui/issues/1334))
- fix: `ProgressBar` chooses the correct direction when directionality is right-to-left ([#1291](https://github.com/bdlukaa/fluent_ui/issues/1291))
Expand Down
2 changes: 1 addition & 1 deletion lib/src/controls/flyouts/menu_flyout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class _MenuFlyoutState extends State<MenuFlyout> {
final itemBox =
subItem.currentContext!.findRenderObject()! as RenderBox;
final parentBox =
parent.widget.root!.context.findRenderObject as RenderBox;
parent.widget.root!.context.findRenderObject()! as RenderBox;
final translation = parentBox.getTransformTo(null).getTranslation();
final offset = Offset(translation[0], translation[1]);
final itemRect =
Expand Down
61 changes: 61 additions & 0 deletions test/flyout_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:ui';

import 'package:fluent_ui/fluent_ui.dart';

import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -228,4 +230,63 @@ void main() {

expect(find.text('Custom Item'), findsOneWidget);
});

testWidgets(
'MenuFlyoutSubItem hover does not throw TypeError on findRenderObject',
(tester) async {
final controller = FlyoutController();

await tester.pumpWidget(
wrapApp(
child: Center(
child: FlyoutTarget(
controller: controller,
child: const Text('Target'),
),
),
),
);

controller.showFlyout<void>(
builder: (context) => MenuFlyout(
items: [
MenuFlyoutSubItem(
text: const Text('Sub Menu'),
items: (context) => [
MenuFlyoutItem(
text: const Text('Sub Item 1'),
onPressed: () {},
),
],
),
MenuFlyoutItem(text: const Text('Item 2'), onPressed: () {}),
],
),
);
await tester.pumpAndSettle();

expect(find.text('Sub Menu'), findsOneWidget);

// Hover over the sub-menu item to trigger its display
final subMenuFinder = find.text('Sub Menu');
final gesture = await tester.createGesture(
kind: PointerDeviceKind.mouse,
);
await gesture.addPointer(location: Offset.zero);
await gesture.moveTo(tester.getCenter(subMenuFinder));
await tester.pumpAndSettle(const Duration(milliseconds: 500));

// The sub-menu should now be showing
expect(find.text('Sub Item 1'), findsOneWidget);

// Move the mouse away from the sub-item to trigger the onHover code path
// that calls findRenderObject() on the parent. This is the code path that
// previously had a bug (missing parentheses on findRenderObject).
await gesture.moveTo(tester.getCenter(find.text('Item 2')));
await tester.pumpAndSettle();

// Should not have thrown a TypeError
await gesture.removePointer();
},
);
}
Loading