MOCKSTACKS
EN
Questions And Answers

More Tutorials









Flutter Stateless Widgets


If you look a user interface, it consists of many Widgets but not many of them have to be smart or interact with the user.

If you look at the default flutter application, there are several widgets but only in fact one Widget with any interactions with the user – the ‘MyHomePage’ Widget that has a counter that counts up when the user clicks on the floating button.

So, the rest of the widgets are used to display something, not interact with the user. That is what stateless widgets are for.

Minimum Code

Here is the minimum code you need for a Stateless Widget:

class EmptyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return <Insert Some Widgets Here>;
}
}

Creation

Stateless widgets are created by a parent widget in its ‘build’ method. They are given the information they need to do their job when they are created.
Stateless widgets receive arguments (information) from their parent widget in the ‘build’ method, which they store in final member variables.

Example

CarWidget("Bmw", "M3",
"https://media.ed.edmundsmedia.com/bmw/m3/2018/oem/2018_bmw_m3_sedan_base_fq_oem_4_150.jpg"),
‘Bmw’
Stored in member variable ‘make’.
‘M3’
Stored in member variable ‘model’.
"https://media.ed.edmundsmedia.com/bmw/m3/2018/oem/2018_bmw_m3_sedan_base_fq_oe
m_4_150.jpg’

Stored in member variable ‘imageSrc’.


Conclusion

In this page (written and validated by ) you learned about Flutter Stateless Widgets . What's Next? If you are interested in completing Flutter tutorial, your next topic will be learning about: Flutter Rendering.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.