Skip to content

felipecastrosales/widgets_vs_functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Widgets vs Methods

In Flutter, it is generally recommended to use classes, specifically widgets, to create UI components. Widgets are classes that define the layout, structure, and appearance of the UI. They are immutable, which means that their properties cannot be changed after they are created. This makes it easy to reason about the state of the UI and to avoid bugs that can occur when state is modified unexpectedly. Additionally, widgets can be composed and reused, which can make it easier to build complex UI.

While you can use methods or functions to create widgets, this approach is less common because it is harder to manage the state and composition of the UI. However, you can create a function that returns a widget, this can be useful in some cases as it can simplify the code and make it more readable.

In summary, using classes (widgets) is the recommended approach when building UI components in Flutter.

TL;DR:
Prefer using classes over functions to make reusable widget-tree.


View more


This project is a small POC, to show in a practical way the behavior and prove the aforementioned theses.