Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.