![]() ![]() It may look complicated but the error is actually in the first line. #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:989:21) #0 Scaffold.of (package:flutter/src/material/scaffold.dart:1785:5) When the exception was thrown, this was the stack: The context used was: MyAwesomeWidgetBrokenĭependencies: ] 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().Ī 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. This introduces a new context from which you can obtain the Scaffold. For an example of this, please see the documentation for Scaffold.of():Ī more efficient solution is to split your build function into several widgets. The simplest is to use a Builder to get a context that is "under" the Scaffold. There are several ways to avoid this problem. This usually happens when the context provided is from the same StatefulWidget as that whose build function actually creates the Scaffold widget being sought. No Scaffold ancestor could be found starting from the context that was passed to Scaffold.of(). ![]() Scaffold.of() called with a context that does not contain a Scaffold. The following assertion was thrown while handling a gesture: When called, each widget you create has a context that becomes the widget's parent.įor example, consider the following code:ĭebug service listening on ws://127.0.0.1:57355/YAQbr2NXIIg=/ws It serves as the bridge for changes in the widget world and updates in the rendering world. Going back to the method signature at the start of the section, “ BuildContext context" provided by the widget’s build method represents the underlying element for the widget. These act as the glue between the immutable widget layer and the mutable render layer.Īs the configuration of a widget changes (for example, a user calls setState which triggers a rebuild), the element looks at the incoming changes and tells the associated render object, "Hey! The user requested a change, it is time for you to update." Bringing It Back to Our Code In the middle of Widgets and RenderObjects sits Elements. Unlike widgets that are cheap and can safely be created and destroyed without any significant performance implications, the same cannot be said for RenderObjects.įor this reason, whenever the configuration of a widget changes, the framework looks at the change and updates the associated RenderObject instead of creating a new one each time. ![]() RenderObjects, on the other hand, are mutable objects that do the heavy lifting of turning the configuration supplied from widgets into pixels users can see and interact with on the screen. The same can’t be said for RenderObjects. Flutter is optimized such that it can easily create and destroy widgets without any significant performance implications. They represent the configuration for RenderObjects. For the purposes of this post, here is what you need to know: Widgets If you’re not too familiar with Flutter’s architecture, read this article for a comprehensive explanation of the inner workings of these trees. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |