Skip to content

Instantly share code, notes, and snippets.

@mhmadip
Created August 22, 2021 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhmadip/d13415415d4b8276208d225495393d6d to your computer and use it in GitHub Desktop.
Save mhmadip/d13415415d4b8276208d225495393d6d to your computer and use it in GitHub Desktop.
22.Quiz: Debug Stateful Widgets
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