Painted levels: being fostered fostered fostered

Tags: “Flutter” “StatelessWidget” “Lifecycle


StatelessWidgetWhat is?

Inherited from widgets, the immutable state is used to describe relatively fixed parts of a UI display, such as a pure display UI, that will not be changed.

abstract class StatelessWidget extends Widget {

  const StatelessWidget({ Key key }) : super(key: key);

  @override
  StatelessElement createElement() => StatelessElement(this);

 @protected
  Widget build(BuildContext context);
}
Copy the code

The StatelessWidget is configured with StatelessElement through its class definition.

Methods an overview

  • buildMethods:

** Description: ** describes the UI represented by the current widget. Call timing: The framework will inject the current StatelessElement using the widget returned by the Build method or select the appropriate update via widget.canupdate. Scenarios: Build can be called in one of three scenarios.

  1. StatelessElementAlso can saystatelessWidget Called when first inserted into the tree;
  2. The fatherWidgetChanged theStatelessElementthewidgetIs passedStatelessElementtheupdateMethod is called to.
  3. It depends onInheritedWidgetWhen change.

conclusion

StatelessWidget through StatelessWidget. The createElement method () to create a StatelessElement, StatelessElement associated StatelessWidget, And configure itself with the StatelessWidget. Where StatelessElement places its build method in the implementation of the StatelessWidget outside of the associated widget. Therefore, its life cycle depends on StatelessElement, and StatelessElement life cycle is relatively simple only build, update.

Just to make sense of itStatelessWidgetI drew a picture of the life cycle ofStatelessElement,Component,ElementThe relationship diagram of.

Ways to focus on us are:

QiShare(GitHub) QiShare(CocoaChina) QiShare(StackOverflow) QiShare(wechat)

Flutter in the Widget

IOS fix [NSURL fileURLWithPath:] # encoding problem Xcode adjust navigation directory font size b Swift 5.1 (21) – Generic Swift 5.1 (20) – Protocol Swift 5.1 (19) – Extended Swift 5.1 (18) – Nested Swift 5.1 (17) – Type Conversion and pattern matching