-
-
Save shameemreza/f597444d573e4790d7cb653df3931908 to your computer and use it in GitHub Desktop.
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
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