Heritage Falodun
3 min readDec 7, 2018

--

FLUTTERING THE STATELESS & STATEFUL WIDGETS

Image:- Ars Technica

... are you a mobile developer who haven’t gotten himself acquainted with Flutter SDK? Dart is the language, Flutter is the framework visit flutter.io and check out this write up later.

"When writing an app, you’ll commonly author new widgets that are subclasses of either

 
StatelessWidget or StatefulWidget, depending on whether your widget manages any state. A widget’s main job is to implement a build function, which describes the widget in terms of other, lower-level widgets. The framework builds those widgets in turn until the process bottoms out in widgets that represent the underlying RenderObject, which computes and describes the geometry of the widget."

An app built with Flutter is basically a "Tree of widgets". Knowing the right time to use these widgets is of utmost importance when fluttering. StatefulWidget unveil a section of the user interface by building other widgets in a sequential manner that describe the user interface more concretely. The same State object are kept by StatefulWidget when moving from one location to another in the tree considering GlobalKey is the key used by it creator. widgets with a GlobalKey can be used in just one location in the tree and it uses just one associated element. State object associated with the widget

are StatefulWidget grafted along with the rest of the subtree, which means the State object is reused and not being recreated in the new location. it’s advisable you utilize StatefulWidget when a section of the user interface is expected to change dynamically. Its all about returning widgets when the user interface is rendered. Receiving input data that can change externally would be possible with StatefulWidgets while internal State can be changed within the widget or re-rendered. Widgets possess lifecycle, i.e (methods that can be added to your classes which will be executed by Flutter).

Image:- Github.com

It follows the procedure of calling the Constructor function followed by the initState() , build(), whereby setState() is always called inside the build() whenever something happens e.g when a button was pressed or when a http request ends, although extra data can be added to your widget, in this case didUpdateWidget() would be called, then build() will be executed again.

StatelessWidgets are useful when the part of the user interface you are describing does not depend on anything other than the configuration information in the object itself and

the BuildContext in which the widget is inflated. Construction function calling only the build() describes a StatelessWidget.

Image :- Github.com

Flutter is all about widgets,user interface are composed from a set of custom and built-in widgets("Components of User Interface"). StatelessWidgets only accept data optionally and render a new widget tree while StatefulWidgets work with both external and internal data which can lead to re-render cycle when subjected to change("state"). Start fluttering, use the right widget. When a mutable State is required,StatefulWidget is ready for the task otherwise StatelessWidget should be considered.



©2019

Code Express

--

--

Heritage Falodun

Software Dev || Bitcoin Consultant & Advocate || GitHub:- https://github.com/Herrytheeagle || Building @DigiOats