Skip to content

Commit f5c6d6e

Browse files
Fixed setState issue in MacosPulldownButton (#585)
Fix setState() called after dispose in MacosPulldownButton
1 parent dc4a902 commit f5c6d6e

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.2.2]
2+
### 🛠 Fixed 🛠
3+
- Fixed setState called after dispose issue in MacosPulldownButton.
4+
15
## [2.2.1]
26
### 🔄 Updated 🔄
37
* Wrap toolbar items with `MacosToolbarPassthrough` to prevent window move or resize when interacting with toolbar items.

‎lib/src/buttons/pulldown_button.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,9 +835,9 @@ class _MacosPulldownButtonState extends State<MacosPulldownButton>
835835
);
836836

837837
navigator.push(_pulldownRoute!).then<void>((_) {
838+
if (!mounted) return;
838839
setState(() => _pullDownButtonState = PulldownButtonState.enabled);
839840
_removeMacosPulldownRoute();
840-
if (!mounted) return;
841841
});
842842

843843
widget.onTap?.call();

‎pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: macos_ui
22
description: Flutter widgets and themes implementing the current macOS design language.
3-
version: 2.2.1
3+
version: 2.2.2
44
homepage: "https://macosui.dev"
55
repository: "https://github.com/GroovinChip/macos_ui"
66

‎test/buttons/pulldown_button_test.dart‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,48 @@ void main() {
5757
expect(mockOnPressedFunction.called, 2);
5858
});
5959

60+
testWidgets('MacosPulldownButton displays correctly items ',
61+
(WidgetTester tester) async {
62+
await tester.pumpWidget(MacosApp(
63+
home: MacosWindow(
64+
child: MacosScaffold(
65+
children: [
66+
ContentArea(
67+
builder: (context, _) {
68+
return Center(
69+
child: MacosPulldownButton(
70+
title: "Menu",
71+
items: [
72+
MacosPulldownMenuItem(
73+
title: const Text('New folder'),
74+
onTap: () {},
75+
),
76+
MacosPulldownMenuItem(
77+
title: const Text('Document'),
78+
onTap: () {},
79+
),
80+
],
81+
),
82+
);
83+
},
84+
),
85+
],
86+
),
87+
),
88+
));
89+
90+
// Verify that the title is rendered on the button.
91+
expect(find.text('Menu'), findsOneWidget);
92+
93+
// tap on the button to open the pulldown menu.
94+
await tester.tap(find.text('Menu'));
95+
await tester.pumpAndSettle();
96+
97+
// Verify that the menu items are displayed.
98+
expect(find.text('New folder'), findsOneWidget);
99+
expect(find.text('Document'), findsOneWidget);
100+
});
101+
60102
testWidgets(
61103
'MacosPulldownButtonItems\' onTap callback is called when defined',
62104
(WidgetTester tester) async {

0 commit comments

Comments
 (0)