stateful widgets

PHOTO EMBED

Fri Aug 04 2023 11:43:55 GMT+0000 (Coordinated Universal Time)

Saved by @manish23 #flutter

import 'package:flutter/material.dart';

class MyStatefulWidget extends StatefulWidget {
  const MyStatefulWidget({super.key});

  @override
  State<MyStatefulWidget> createState() => _MyStatefulWidgetState();
}

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int count = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Text("$count"),
      ),
      floatingActionButton: FloatingActionButton(onPressed: (){
        setState(() {
          count++;
        });
      },
      child: const Icon(Icons.add),),
    );
  }
}
content_copyCOPY