Skip to content

Commit

Permalink
fix: MenuButtonBuilder only find render object when mounted (#449)
Browse files Browse the repository at this point in the history
In some cases you'll get the following without this fix applied:
```
This widget has been unmounted, so the State no longer has a context (and should be considered defunct). 
```
  • Loading branch information
spydon authored Oct 14, 2024
1 parent eaa14c5 commit e72658f
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/ubuntu_widgets/lib/src/menu_button_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ class _MenuButtonBuilderState<T> extends State<MenuButtonBuilder<T>> {

void _updateSize() {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;

final size = (context.findRenderObject() as RenderBox?)?.size;
if (_size != size) {
setState(() => _size = size);
Expand Down

0 comments on commit e72658f

Please sign in to comment.