diff --git a/CHANGELOG.md b/CHANGELOG.md index f781951c..10816f76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [2.2.2] +### 🛠 Fixed 🛠 +- Fixed setState called after dispose issue in MacosPulldownButton. + ## [2.2.1] ### 🔄 Updated 🔄 * Wrap toolbar items with `MacosToolbarPassthrough` to prevent window move or resize when interacting with toolbar items. diff --git a/lib/src/buttons/pulldown_button.dart b/lib/src/buttons/pulldown_button.dart index 74e7b20b..e0055c25 100644 --- a/lib/src/buttons/pulldown_button.dart +++ b/lib/src/buttons/pulldown_button.dart @@ -835,9 +835,9 @@ class _MacosPulldownButtonState extends State ); navigator.push(_pulldownRoute!).then((_) { + if (!mounted) return; setState(() => _pullDownButtonState = PulldownButtonState.enabled); _removeMacosPulldownRoute(); - if (!mounted) return; }); widget.onTap?.call(); diff --git a/pubspec.yaml b/pubspec.yaml index be810937..886bb6b4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: macos_ui description: Flutter widgets and themes implementing the current macOS design language. -version: 2.2.1 +version: 2.2.2 homepage: "https://macosui.dev" repository: "https://github.com/GroovinChip/macos_ui" diff --git a/test/buttons/pulldown_button_test.dart b/test/buttons/pulldown_button_test.dart index 0e5b7a88..c61d5388 100644 --- a/test/buttons/pulldown_button_test.dart +++ b/test/buttons/pulldown_button_test.dart @@ -57,6 +57,48 @@ void main() { expect(mockOnPressedFunction.called, 2); }); + testWidgets('MacosPulldownButton displays correctly items ', + (WidgetTester tester) async { + await tester.pumpWidget(MacosApp( + home: MacosWindow( + child: MacosScaffold( + children: [ + ContentArea( + builder: (context, _) { + return Center( + child: MacosPulldownButton( + title: "Menu", + items: [ + MacosPulldownMenuItem( + title: const Text('New folder'), + onTap: () {}, + ), + MacosPulldownMenuItem( + title: const Text('Document'), + onTap: () {}, + ), + ], + ), + ); + }, + ), + ], + ), + ), + )); + + // Verify that the title is rendered on the button. + expect(find.text('Menu'), findsOneWidget); + + // tap on the button to open the pulldown menu. + await tester.tap(find.text('Menu')); + await tester.pumpAndSettle(); + + // Verify that the menu items are displayed. + expect(find.text('New folder'), findsOneWidget); + expect(find.text('Document'), findsOneWidget); + }); + testWidgets( 'MacosPulldownButtonItems\' onTap callback is called when defined', (WidgetTester tester) async {