StateLess Widget in Flutter
Arpan Bhatia
8+ Years Experience, I am looking for New Opportunities, Contact at: 7906156955 || Sr. Developer @Team Computers Mobile Team || Android || Core Java || Kotlin || Flutter || Dart || Jetpack Components ||Jetpack Compose UI
- Stateless widget simply means the widget that will be return in this class will not contain any state and it will never change in future.
- A widget that does not require mutable state.
- Stateless widget are useful when the part of the user interface you are describing does not depend on anything other than the configuration information in the object itself and the BuildContext in which the widget is inflated. For compositions that can change dynamically, e.g. due to having an internal clock-driven state, or depending on some system state, consider using StatefulWidget.
- StateLess Widgets override build() method, which always return a Widget.
Follow the Code Example to understand this:
import 'dart:ui'; import 'package:flutter/material.dart'; //UI Element known as Widget in Flutter as Center,Text,MaterialApp,Material,Scaffold,AppBar void main(){ runApp( MyFlutterApp() ); } class MyFlutterApp extends StatelessWidget{ @override Widget build(BuildContext context) { return new MaterialApp( title:"MyFlutter App", home: Scaffold( appBar: AppBar(title: Text("MainScreen"),), body: new Material(color:Colors.lightBlueAccent, child: Center( child: Text( "Hello Flutter", textDirection: TextDirection.ltr, textScaleFactor :1.5, style: TextStyle(color:Colors.white,fontSize: 40.0), ) ), ) ) ) ; } }