Created
August 22, 2021 16:54
-
-
Save mhmadip/d13415415d4b8276208d225495393d6d to your computer and use it in GitHub Desktop.
22.Quiz: Debug Stateful Widgets
This file contains 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
import 'package:flutter/material.dart'; | |
void main() => runApp(MyApp()); | |
class MyApp extends StatelessWidget { @override | |
Widget build(BuildContext context) { | |
return MaterialApp( home: MyHomePage(), | |
); } | |
} | |
class MyHomePage extends StatefulWidget { MyHomePage(); | |
@override | |
createState() => _MyHomePageState(); | |
} | |
class _MyHomePageState extends State<MyHomePage> { int _counter = 0; | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( body: Center( | |
child: Column( children: <Widget>[ | |
Text( | |
'You have pushed the button this many times:', | |
), Text( | |
'$_counter', | |
), | |
], ), | |
), | |
floatingActionButton: FloatingActionButton( | |
onPressed: () { | |
// I've added the setState method here, so whenever the user click on the Button, then it will increase counter and update on UI | |
setState(() { | |
_counter++; | |
}); | |
}, | |
child: Icon(Icons.add), ), | |
); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment