Flutter में दो मूलभूत widget प्रकार हैं: StatelessWidget (immutable, कोई आंतरिक state नहीं जो बदलती है) और StatefulWidget (mutable state रख और update कर सकता है, state बदलने पर rebuild होता है)। सही चुनना Flutter UIs बनाने के लिए मूलभूत है।
StatelessWidget — कोई बदलती state नहीं
// a StatelessWidget: just describes UI based on its inputs (immutable, no internal state)
class Greeting extends StatelessWidget {
final String name;
const Greeting(this.name);
@override
Widget build(BuildContext context) {
return Text('Hello, $name'); // UI depends only on inputs, never changes itself
}
}
// → use for UI that doesn't change on its own (static content, displays based on inputs)
