I have a screen made using Stateless Widget.
I want to run some code when the screen is loaded or when the Stateless widget is created.
In android we could do this in onCreate() method.
i.e. is there some equivalent of onCreate() in flutter.
The terminology for this is "mount". So you want to run the code when the widget is mounted. In Flutter, all widgets have a mounted
property and it turns true when the buildContext
is assigned to a widget.
But I don't think you can do something to workaround with that property.
bool get mounted => _element != null;
I think what you can do is turn your widget into Stateful widget and use initState()
initState
method, if you are modifying the state of the widget.onCreate
?void main() => {startAlarm(); runApp(MyApp());}
created
.. why not just use the constructor?