In the Flutter job interviews, sometimes I am asked how we can rebuild the StatelessWidget
and the answer to this is to call the markNeedsBuild()
method of the widget's Element
or BuildContext
.
So the question is, are there any cases when we need to rebuild a StatelessWidget
and it's better to use a StatelessWidget
instead of the StatefulWidget
?
I found cases where people wanted to rebuild the StatelessWidget
, such as How to invoke a rebuild of a stateless widget?, but in all these cases it was better to use StatefulWidget
or state management instead.
The whole purpose of the StatelessWidget
is not to rebuild.
If you require rebuild you have to use StatefullWidget
.
I guess the interviewers are trying to trick you xD