Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delay call to setState with addPostFrameCallback #1185

Merged
merged 1 commit into from
Sep 25, 2024

Conversation

atavism
Copy link
Contributor

@atavism atavism commented Sep 24, 2024

For https://github.com/getlantern/engineering/issues/1652

══╡ EXCEPTION CAUGHT BY FOUNDATION LIBRARY ╞════════════════════════════════════════════════════════
The following assertion was thrown while dispatching notifications for ValueNotifier<bool>:
setState() or markNeedsBuild() called during build.
This VPNSwitch widget cannot be marked as needing to build because the framework is already in the
process of building widgets. A widget can be marked as needing to be built during the build phase
only if one of its ancestors is currently building. This exception is allowed because the framework
builds parent widgets before children, which means a dirty descendant will always be built.
Otherwise, the framework might not visit this widget during this build phase.
The widget on which setState() or markNeedsBuild() was called was:
  VPNSwitch
The widget which was currently being built when the offending call was made was:
  FfiValueBuilder<String>

When the exception was thrown, this was the stack:
#0      Element.markNeedsBuild.<anonymous closure> (package:flutter/src/widgets/framework.dart:5177:9)
#1      Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:5189:6)
#2      State.setState (package:flutter/src/widgets/framework.dart:1223:15)
#3      _VPNSwitchState.build.<anonymous closure>.<anonymous closure> (package:lantern/vpn/vpn_switch.dart:118:15)
#4      _AdvancedSwitchState._handleControllerValueChanged (package:flutter_advanced_switch/flutter_advanced_switch.dart:279:23)
#5      ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:437:24)
#6      ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:559:5)
#7      _AdvancedSwitchState.didUpdateWidget (package:flutter_advanced_switch/flutter_advanced_switch.dart:108:24)
#8      StatefulElement.update (package:flutter/src/widgets/framework.dart:5789:55)
#9      Element.updateChild (package:flutter/src/widgets/framework.dart:3941:15)
#10     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5642:16)
#11     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5780:11)
#12     Element.rebuild (package:flutter/src/widgets/framework.dart:5333:7)
#13     BuildScope._tryRebuild (package:flutter/src/widgets/framework.dart:2693:15)
#14     BuildScope._flushDirtyElements (package:flutter/src/widgets/framework.dart:2752:11)
#15     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:3048:18)
#16     WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:1162:21)
#17     RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:468:5)
#18     SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1397:15)
#19     SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1318:9)
#20     SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1176:5)
#21     _invoke (dart:ui/hooks.dart:312:13)
#22     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:419:5)
#23     _drawFrame (dart:ui/hooks.dart:283:31)

Copy link
Contributor

@jigar-f jigar-f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jigar-f jigar-f merged commit e0780f7 into main Sep 25, 2024
2 checks passed
@jigar-f jigar-f deleted the atavism/macos-crash-fix branch September 25, 2024 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants