The state can be defined as information about a widget. The state may change during the lifetime of a widget. Changes made in a Flutter page due to certain clicks or changes in flutter behavior and structure in a single page known as State. Futter can have two types of states as Stateless Widget and Stateful Widget.

Stateless Widget in Flutter

Stateless widget is the widget in Flutter in which program states cannot be changed or the structure of the page remains the same. A stateless widget is used when we don't have to change the page occurrence/state in the flutter application. Up to this Flutter series part, we have created stateless widgets.

import "package:flutter/material.dart";

void main() => runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MyApp(),));

class MyApp extends StatelessWidget { //Stateless Widget
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text("Review2Tech Application"),
        ),
        body: Container(
          child: Text("This is the stateless widget example"),
        ),
    );
  }
}

//Note: Shortcut to make Stateless Widget type "stless" and press enter

Stateful Widget in Flutter

Stateful widget is a widget in a flutter in which the states of the application can be changed or the structure or content of the application can be changed without changing the code. A stateful widget is a mostly used widget in Flutter application development. For example, Checkbox states should be changed from on to off, radio button states, slider state, etc.

import "package:flutter/material.dart";

void main() => runApp(MaterialApp(debugShowCheckedModeBanner: false, home: MyApp(),));

class MyApp extends StatefulWidget { //Stateful Widget
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("This is AppBar"),
      ),
      body: Container(
        child: Text("This is Stateful Widget example"),
      ),
    );
  }
}

//Note: Shortcut to make stateful widget type "stful" and press enter

Complete Flutter Series List: Click here 

Categories: Blog Tags: flutter, review2tech flutter series, flutter states, stateless widget, statefull widget, flutter android, flutter ios


0 Comments

Leave a comment