Skip to content

Instantly share code, notes, and snippets.

@shameemreza
Created August 27, 2020 15:57
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 shameemreza/f597444d573e4790d7cb653df3931908 to your computer and use it in GitHub Desktop.
Save shameemreza/f597444d573e4790d7cb653df3931908 to your computer and use it in GitHub Desktop.
class Counter extends StatefulWidget {
@override
_CounterState createState() => _CounterState();
}
class _CounterState extends State<Counter> {
int count = 0;
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
CounterButton(() {
setState(() {
count++;
});
}),
CounterText(count),
],
);
}
}
class CounterText extends StatelessWidget {
CounterText(this.count);
final int count;
@override
Widget build(BuildContext context) {
return Text('Value: ${count ?? "}');
}
}
class CounterButton extends StatelessWidget {
CounterButton(this.onPressed);
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return RaisedButton(
child: Text('+'),
onPressed: onPressed,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment