concept

  • Almost all objects in FLUTTER are widgets. Unlike the “controls” in native development, widgets in Flutter are broader in concept. They can represent not only UI elements, but also functional components such as gesture detectionGestureDetectorWidget, for application topic data transferTheme, etc.

The Widget with the Element

  • A Widget does not actually represent the display element that is eventually drawn on the device screen, but rather displays configuration data for the element. In fact, the classes in Flutter that really represent the elements displayed on the screen areElementThat is, widgets are just descriptionsElementA configuration of

Stateless Widget

  • The StatelessWidget is relatively simple and inherits fromWidgetTo rewrite thecreateElement()Methods:
  • The StatelessWidget is used for scenarios that do not require state maintenance, and is typically found inbuildMethod to build the UI by nesting other widgets, recursively building their nested widgets during the build process

Stateful Widget

Like the StatelessWidget, the StatefulWidget inherits from the Widget class and overwrites the createElement() method, except that it returns a different Element object

In addition, a new interface createState() has been added to the StatefulWidget class.

State

A StatefulWidget class corresponds to a State class. State represents the State to be maintained by its corresponding StatefulWidget. State information stored in State can be:

  1. It can be read synchronously during Widget build.
  2. The widget can be changed during its life cycle and can be called manually when State is changedsetState()Method notifies the Flutter framework of a state change, which the Flutter framework calls again when it receives a messagebuildMethod to rebuild the Widget tree to update the UI.

Introduction to the Flutter Widget library

Based on the widget

  • Text, Row, Column, Container

Material widget

Cupertino widget