Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/felipecastrosales/widgets_vs_functions
🆚 Flutter | Widgets vs Methods
https://github.com/felipecastrosales/widgets_vs_functions
context dart flutter flutter-app flutter-apps flutter-examples flutter-tips functions good-practices lifecycle methods tips tips-and-tricks tricks widgets
Last synced: 29 days ago
JSON representation
🆚 Flutter | Widgets vs Methods
- Host: GitHub
- URL: https://github.com/felipecastrosales/widgets_vs_functions
- Owner: felipecastrosales
- Created: 2023-01-10T22:38:07.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-07-06T16:29:18.000Z (6 months ago)
- Last Synced: 2024-07-06T17:42:04.091Z (6 months ago)
- Topics: context, dart, flutter, flutter-app, flutter-apps, flutter-examples, flutter-tips, functions, good-practices, lifecycle, methods, tips, tips-and-tricks, tricks, widgets
- Language: C++
- Homepage:
- Size: 300 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 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
- [What is the difference between functions and classes to create reusable widgets?](https://stackoverflow.com/questions/53234825/what-is-the-difference-between-functions-and-classes-to-create-reusable-widgets)
- [Methods vs Stateless Widget to return widgets](https://www.reddit.com/r/FlutterDev/comments/mp4xpx/methods_vs_stateless_widget_to_return_widgets/)
- [Splitting widgets to methods is an antipattern](https://iiro.dev/splitting-widgets-to-methods-performance-antipattern/)
- [🔷 Widgets vs. Helper Methods ✨](https://twitter.com/flutterdev/status/1469374537481351173)
- [Flutter Performance Tip: Keep Your Build Method Pure](https://www.funwithflutter.dev/flutter-keep-your-build-method-pure/)
- [Widgets vs helper methods | Decoding Flutter](https://www.youtube.com/watch?v=IOyq-eTRhvo)
- [🇧🇷 Não use functions para criar widgets](https://www.youtube.com/watch?v=FMrK4owucBU)---
>
This project is a small POC, to show in a practical way the behavior and prove the aforementioned theses.