Last active
November 20, 2021 15:43
-
-
Save gabrielgatu/74d288ea912a85575e6a5adff443a3dc to your computer and use it in GitHub Desktop.
[Flutter2Start - StatelessWidget vs StatefulWidget] #flutter2start
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ignore_for_file: use_key_in_widget_constructors, prefer_const_constructors, prefer_const_literals_to_create_immutables | |
| import 'package:flutter/material.dart'; | |
| void main() { | |
| runApp(App()); | |
| } | |
| class App extends StatelessWidget { | |
| @override | |
| Widget build(BuildContext context) { | |
| return MaterialApp( | |
| home: HomePage(), | |
| ); | |
| } | |
| } | |
| class HomePage extends StatefulWidget { | |
| @override | |
| _HomePageState createState() => _HomePageState(); | |
| } | |
| class _HomePageState extends State<HomePage> { | |
| int counter = 0; | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text("Lista d'attesa!"), | |
| centerTitle: true, | |
| ), | |
| body: Center( | |
| child: Text( | |
| "Persone in lista d'attesa: $counter", | |
| style: TextStyle( | |
| fontSize: 20, | |
| fontWeight: FontWeight.bold, | |
| ), | |
| ), | |
| ), | |
| floatingActionButton: FloatingActionButton( | |
| onPressed: () { | |
| setState(() { | |
| counter = counter + 1; | |
| }); | |
| }, | |
| child: Icon(Icons.plus_one), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment