The widget property is a part of the State class, which inherits it in the _YourWidgetState class. This _YourWidgetState class is a subclass of the State class.
When you examine the State class reference, you will find:
abstract class State<T extends StatefulWidget> with Diagnosticable {
get widget => _widget!;
T? _widget;
}
In this context, T represents the type parameter of the State class, which, in this case, is your custom widget class. Consequently, the widget property within the State class refers to an instance of your custom widget class.
Let's consider the example of the BiggerText widget:
class BiggerText extends StatefulWidget {
final String text;
const BiggerText({Key? key, required this.text}) : super(key: key);
@override
State<BiggerText> createState() => _BiggerTextState();
}
class _BiggerTextState extends State<BiggerText> {
double _textSize = 16.0;
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(**widget.text**, style: TextStyle(fontSize: _textSize)),
],
);
}
}
based on the example above
class _BiggerTextState extends State<BiggerText>
The code signifies that _BiggerTextState inherits the widget property from the State class, thanks to being a subclass of the State class.
Within the State class, the widget property represents an instance of the generic type T, which, in this case, corresponds to the BiggerText class. As a result, the widget property in this context is an instance of the BiggerText class itself.
So, when you use, for instance, widget.text, you're accessing a property of the BiggerText class.