StateLess Widget in Flutter

StateLess Widget in Flutter

  1. 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.
  2. A widget that does not require mutable state.
  3. 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.
  4. 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),
                  )





              ),
            )

        )

    ) ;
  }





}

要查看或添加评论,请登录

Arpan Bhatia的更多文章

  • Closures in Flutter

    Closures in Flutter

    A Closure is Function in Flutter that capture a value from its surroundings scope, even after scope exited. It is…

  • Higher Order Functions in Dart & Flutter:

    Higher Order Functions in Dart & Flutter:

    Higher Functions are the function that are used to make our code more concise, flexible and reusable. A higher order…

  • Extensions in Flutter

    Extensions in Flutter

    In Flutter extensions allowed to you to add some new functionality to existing class without modified their original…

  • Mixin in Dart:

    Mixin in Dart:

    As the name suggest Mixin is use to mix it with some thing .In Flutter Mixin is way to reuse a code into multiple class…

    1 条评论
  • Kotlin Flows and Channels

    Kotlin Flows and Channels

    In modern software development, asynchronous programming has become a crucial aspect of building responsive and…

    1 条评论

社区洞察

其他会员也浏览了