E.1. What’s the equivalent of a view in Flutter?

In Android, you create all your UI elements with views. In Flutter, everything is a widget, and that’s the closest comparison to a view. (Widgets aren’t exactly the same as views, because they also handle more than just UI, but widgets are used to construct UI of mobile apps also.) For our intent and purpose, they’re close enough. So, if widgets are views, what are the differences?

First, widgets are immutable. They’re light-weight blueprints for the UI that are destroyed as soon as they need to be changed. Every time the configuration or state of a widget changes, Flutter redraws the relevant widget tree. But widgets are just descriptions for actual elements and don’t get drawn to the screen directly.

Also, because of the immutability, a widget doesn’t change its child widgets. There is no equivalent to addChild() or removeChild(). Rather than saying, “Hey, UI element, remove child ABC and replace it with XYZ,” you just redraw the UI element with the child XYZ.

Note

Widgets and updating the “view” are explained in detail in chapters 1 and 3.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.27.171