I am confused at the fact that, are the classes like TextStyle, MainAxisAlignment are widgets or just some classes?
If they are not widgets, how can I distinguish them?
I am confused at the fact that, are the classes like TextStyle, MainAxisAlignment are widgets or just some classes?
If they are not widgets, how can I distinguish them?
4
Answers
Widget is just a kind of class. I will write some examples:
As I see, the frameworks nowaday use component styles, web or mobile applications are designed in components. Widget is a component, and it belongs to UI class.
this is an example using
TextStyle
andText
widgets in Flutter.In this example:
TextStyle
is a configuration class used within theText
widget to define the style of the displayed text.Text is a widget that displays a string of text on the screen.
The
TextStyle
class configures the appearance of the text displayed by theText
widget. In this case:color
sets the text color to blue.fontSize
sets the font size to 24.fontWeight
sets the font weight to bold.While
TextStyle
itself is not a widget, it’s crucial for specifying how theText
widget should display its content. TheText
widget is the actual UI element that renders text on the screen, andTextStyle
is used as a property to style that text.All widgets are class, but not all class are widget.
You can check widgets-library..
StatefulWidget
orStatelessWidget
can be called both widget and class.If it is not directly extend the
Widget
class, you will find an ancestor doing it, e.gSingleChildRenderObjectWidget
orMultiChildRenderObjectWidget
extends theRenderObjectWidget
which parent isWidget
.There are many classes which is not a widget ,
DateTime
,TextSpan
,TextEditingController
,Animation
…