D.1. What’s the equivalent of UIView in Flutter?

In iOS, you create your UI with view objects that are instances of UIView. In Flutter, everything is a widget, and that’s the closest comparison to a UIView. They aren’t exactly the same because they handle more, but they are used to construct UIs. For our intent and purpose, they’re close enough. So, if widgets are UIViews, 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. 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
18.225.117.233