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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [2.2.1]
### 🔄 Updated 🔄
* Wrap toolbar items with `MacosToolbarPassthrough` to prevent window move or resize when interacting with toolbar items.

## [2.2.0+3]
* Address DCM lints:
* Prefer `const BorderRadius.all`
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.0+3"
version: "2.2.1"
macos_window_utils:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion lib/src/buttons/toolbar/toolbar_icon_button.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:macos_ui/macos_ui.dart';
import 'package:macos_ui/src/library.dart';
import 'package:macos_window_utils/widgets/macos_toolbar_passthrough.dart';

/// An icon button suitable for the toolbar.
class ToolBarIconButton extends ToolbarItem {
Expand Down Expand Up @@ -99,7 +100,7 @@ class ToolBarIconButton extends ToolbarItem {
if (tooltipMessage != null) {
iconButton = MacosTooltip(message: tooltipMessage!, child: iconButton);
}
return iconButton;
return MacosToolbarPassthrough(child: iconButton);
} else {
return ToolbarOverflowMenuItem(label: label, onPressed: onPressed);
}
Expand Down
3 changes: 2 additions & 1 deletion lib/src/buttons/toolbar/toolbar_pulldown_button.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:macos_ui/macos_ui.dart';
import 'package:macos_ui/src/library.dart';
import 'package:macos_window_utils/widgets/macos_toolbar_passthrough.dart';

/// A pulldown button suitable for the toolbar.
class ToolBarPullDownButton extends ToolbarItem {
Expand Down Expand Up @@ -72,7 +73,7 @@ class ToolBarPullDownButton extends ToolbarItem {
child: pulldownButton,
);
}
return pulldownButton;
return MacosToolbarPassthrough(child: pulldownButton);
} else {
// We should show a submenu for the pulldown button items.
final subMenuKey = GlobalKey<ToolbarPopupState>();
Expand Down
3 changes: 2 additions & 1 deletion lib/src/layout/toolbar/custom_toolbar_item.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:macos_ui/macos_ui.dart';
import 'package:macos_ui/src/library.dart';
import 'package:macos_window_utils/widgets/macos_toolbar_passthrough.dart';

/// A custom widget for the toolbar.
class CustomToolbarItem extends ToolbarItem {
Expand Down Expand Up @@ -66,7 +67,7 @@ class CustomToolbarItem extends ToolbarItem {
if (tooltipMessage != null) {
widget = MacosTooltip(message: tooltipMessage!, child: widget);
}
return widget;
return MacosToolbarPassthrough(child: widget);
} else {
return (inOverflowedBuilder != null)
? inOverflowedBuilder!(context)
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: macos_ui
description: Flutter widgets and themes implementing the current macOS design language.
version: 2.2.0+3
version: 2.2.1
homepage: "https://macosui.dev"
repository: "https://github.com/GroovinChip/macos_ui"

Expand Down
259 changes: 259 additions & 0 deletions test/buttons/toolbar_icon_button_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:macos_window_utils/widgets/macos_toolbar_passthrough.dart';

import '../mocks.dart';

void main() {
late MockOnPressedFunction mockOnPressedFunction;

setUp(() {
mockOnPressedFunction = MockOnPressedFunction();
});

group('ToolBarIconButton tests', () {
testWidgets(
'ToolBarIconButton is wrapped with MacosToolbarPassthrough when in toolbar',
(tester) async {
await tester.pumpWidget(
MacosApp(
home: MacosWindow(
child: MacosScaffold(
toolBar: ToolBar(
title: const Text('Test'),
actions: [
ToolBarIconButton(
label: 'Add',
icon: const MacosIcon(CupertinoIcons.add),
showLabel: false,
onPressed: mockOnPressedFunction.handler,
),
],
),
children: [
ContentArea(
builder: (context, _) {
return const Center(child: Text('Content'));
},
),
],
),
),
),
);

await tester.pumpAndSettle();

// Verify that MacosToolbarPassthrough is present in the widget tree
expect(find.byType(MacosToolbarPassthrough), findsWidgets);

// Verify that the button itself is still present
expect(find.byType(MacosIconButton), findsWidgets);
},
);

testWidgets(
'ToolBarIconButton with label is wrapped with MacosToolbarPassthrough',
(tester) async {
await tester.pumpWidget(
MacosApp(
home: MacosWindow(
child: MacosScaffold(
toolBar: ToolBar(
title: const Text('Test'),
actions: [
ToolBarIconButton(
label: 'Add',
icon: const MacosIcon(CupertinoIcons.add),
showLabel: true,
onPressed: mockOnPressedFunction.handler,
),
],
),
children: [
ContentArea(
builder: (context, _) {
return const Center(child: Text('Content'));
},
),
],
),
),
),
);

await tester.pumpAndSettle();

// Verify that MacosToolbarPassthrough is present
expect(find.byType(MacosToolbarPassthrough), findsWidgets);

// Verify the label is displayed
expect(find.text('Add'), findsOneWidget);
},
);

testWidgets(
'ToolBarIconButton with tooltip is wrapped with MacosToolbarPassthrough',
(tester) async {
await tester.pumpWidget(
MacosApp(
home: MacosWindow(
child: MacosScaffold(
toolBar: ToolBar(
title: const Text('Test'),
actions: [
ToolBarIconButton(
label: 'Add',
icon: const MacosIcon(CupertinoIcons.add),
showLabel: false,
tooltipMessage: 'Add item',
onPressed: mockOnPressedFunction.handler,
),
],
),
children: [
ContentArea(
builder: (context, _) {
return const Center(child: Text('Content'));
},
),
],
),
),
),
);

await tester.pumpAndSettle();

// Verify that MacosToolbarPassthrough is present
expect(find.byType(MacosToolbarPassthrough), findsWidgets);

// Verify tooltip is present
expect(find.byType(MacosTooltip), findsOneWidget);
},
);

testWidgets(
'ToolBarIconButton still functions when wrapped with MacosToolbarPassthrough',
(tester) async {
await tester.pumpWidget(
MacosApp(
home: MacosWindow(
child: MacosScaffold(
toolBar: ToolBar(
title: const Text('Test'),
actions: [
ToolBarIconButton(
label: 'Add',
icon: const MacosIcon(CupertinoIcons.add),
showLabel: false,
onPressed: mockOnPressedFunction.handler,
),
],
),
children: [
ContentArea(
builder: (context, _) {
return const Center(child: Text('Content'));
},
),
],
),
),
),
);

await tester.pumpAndSettle();

// Verify that MacosToolbarPassthrough is present
expect(find.byType(MacosToolbarPassthrough), findsWidgets);

// Verify that the button is present and functional
expect(find.byType(MacosIconButton), findsWidgets);
},
);

testWidgets(
'Multiple ToolBarIconButtons each have their own MacosToolbarPassthrough',
(tester) async {
await tester.pumpWidget(
MacosApp(
home: MacosWindow(
child: MacosScaffold(
toolBar: ToolBar(
title: const Text('Test'),
actions: [
ToolBarIconButton(
label: 'Add',
icon: const MacosIcon(CupertinoIcons.add),
showLabel: false,
onPressed: mockOnPressedFunction.handler,
),
ToolBarIconButton(
label: 'Remove',
icon: const MacosIcon(CupertinoIcons.minus),
showLabel: false,
onPressed: mockOnPressedFunction.handler,
),
],
),
children: [
ContentArea(
builder: (context, _) {
return const Center(child: Text('Content'));
},
),
],
),
),
),
);

await tester.pumpAndSettle();

// Each button should have its own MacosToolbarPassthrough wrapper
expect(find.byType(MacosToolbarPassthrough), findsWidgets);
expect(find.byType(MacosIconButton), findsWidgets);
},
);

testWidgets(
'Disabled ToolBarIconButton is still wrapped with MacosToolbarPassthrough',
(tester) async {
await tester.pumpWidget(
MacosApp(
home: MacosWindow(
child: MacosScaffold(
toolBar: const ToolBar(
title: Text('Test'),
actions: [
ToolBarIconButton(
label: 'Add',
icon: MacosIcon(CupertinoIcons.add),
showLabel: false,
onPressed: null,
),
],
),
children: [
ContentArea(
builder: (context, _) {
return const Center(child: Text('Content'));
},
),
],
),
),
),
);

await tester.pumpAndSettle();

// Disabled button should still be wrapped
expect(find.byType(MacosToolbarPassthrough), findsWidgets);
expect(find.byType(MacosIconButton), findsWidgets);
},
);
});
}
Loading
Loading