Problem Statement
What is the main difference between StatelessWidget and StatefulWidget?
Explanation
StatelessWidget is immutable and cannot change once built - all its properties are final, and it only rebuilds when the parent widget changes or when external data changes. Use StatelessWidget for UI that depends only on configuration information (constructor parameters) and doesn't need to change dynamically based on user interaction or other events.
StatefulWidget maintains mutable state that can change over time through a separate State object. The widget itself is still immutable, but it creates a State object that persists across rebuilds and can hold mutable data. When you call setState(), Flutter rebuilds the widget with the new state values, updating the UI.
Examples: Use StatelessWidget for static text, icons, or layouts that don't change. Use StatefulWidget for forms, animations, counters, or any UI that responds to user input, timers, or streams. The State object lifecycle is managed by Flutter and persists even when the widget is rebuilt.
