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

FlutterErrorscaffold #25

Closed
devrnt opened this issue Jul 10, 2019 · 0 comments
Closed

FlutterErrorscaffold #25

devrnt opened this issue Jul 10, 2019 · 0 comments
Labels
bug Something isn't working

Comments

@devrnt
Copy link
Owner

devrnt commented Jul 10, 2019

FlutterError: Scaffold.of() called with a context that does not contain a Scaffold.
No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of(). This usually happens when the context provided is from the same StatefulWidget as that whose build function actually creates the Scaffold widget being sought.
There are several ways to avoid this problem. The simplest is to use a Builder to get a context that is "under" the Scaffold. For an example of this, please see the documentation for Scaffold.of():
  https://docs.flutter.io/flutter/material/Scaffold/of.html
A more efficient solution is to split your build function into several widgets. This introduces a new context from which you can obtain the Scaffold. In this solution, you would have an outer widget that creates the Scaffold populated by instances of your new inner widgets, and then in these inner widgets you would use Scaffold.of().
A less elegant but more expedient solution is assign a GlobalKey to the Scaffold, then use the key.currentState property to obtain the ScaffoldState rather than using the Scaffold.of() function.
The context used was:
  MovieDetails
  File "scaffold.dart", line 1155, in Scaffold.of
  File "widget_helper.dart", line 45, in WidgetHelper.showSnackbar
  File "movie_details_screen.dart", line 303, in MovieDetailsState._downloadFile
  File "<asynchronous suspension>"
  File "movie_details_screen.dart", line 311, in MovieDetailsState._downloadFile
  File "<asynchronous suspension>"
  File "movie_details_screen.dart", line 291, in MovieDetailsState._buildSubtitleDropDown.<fn>
  File "ink_well.dart", line 511, in _InkResponseState._handleTap
  File "ink_well.dart", line 566, in _InkResponseState.build.<fn>
  File "recognizer.dart", line 166, in GestureRecognizer.invokeCallback
  File "tap.dart", line 240, in TapGestureRecognizer._checkUp
  File "tap.dart", line 211, in TapGestureRecognizer.acceptGesture
  File "arena.dart", line 156, in GestureArenaManager.sweep
  File "binding.dart", line 225, in _WidgetsFlutterBinding&BindingBase&GestureBinding.handleEvent
  File "binding.dart", line 199, in _WidgetsFlutterBinding&BindingBase&GestureBinding.dispatchEvent
  File "binding.dart", line 156, in _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerEvent
  File "binding.dart", line 102, in _WidgetsFlutterBinding&BindingBase&GestureBinding._flushPointerEventQueue
  File "binding.dart", line 86, in _WidgetsFlutterBinding&BindingBase&GestureBinding._handlePointerDataPacket
  File "zone.dart", line 1136, in _rootRunUnary
  File "zone.dart", line 1029, in _CustomZone.runUnary
  File "zone.dart", line 931, in _CustomZone.runUnaryGuarded
  File "hooks.dart", line 233, in _invoke1
  File "hooks.dart", line 154, in _dispatchPointerDataPacket
@devrnt devrnt added the bug Something isn't working label Jul 10, 2019
devrnt added a commit that referenced this issue Jul 10, 2019
@devrnt devrnt closed this as completed Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant