Reputation: 385
I am new to flutter and was studying with StatefulWidget
but I couldn't clearly understand the following term
class MyApp extends StatefulWidget
{
@override
_myState createState() => _myState();
}
I tried this
@override
return _myState();
And its clear to me, but we user _myState before createState() method.
Upvotes: 1
Views: 1570
Reputation: 3410
_myState
here is actually a type, not a variable name.
This function here
@override
_myState createState() => _myState();
is equivalent to:
@override
_myState createState() {
return new _myState();
}
where the class _myState
is likely defined as so:
class _myState extends State<MyApp> {
...
}
In dart, you do not need to use new
(optional) to instantiate an object.
However by naming convention class names should be in PascalCase, in this case _MyState
instead of _myState
which will help make it more readable, especially in your case here.
Upvotes: 2