What is the reason behind having a StatelessWidget?

Posted by Jessica Taylor | Updated on

What is the reason behind having a StatelessWidget?

If your widget manages state, you should use a StatefulWidget with an associated State object to store the state.

If your widget doesn’t manage any state, and its build method only depends on its constructor arguments (or Inherited widgets such as Theme), it’s better to use a StatelessWidget. StatelessWidget requires defining fewer classes and invoking fewer methods, so it should be faster and more maintainable than an equivalent StatefulWidget that doesn’t cache anything in its state.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers