Created
September 3, 2020 11:58
-
-
Save agnamc9/761970ee202b352823cbc62047b52c9c 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
import 'package:flutter/material.dart'; | |
class CompoundWidget extends StatefulWidget { | |
final Function onChanged; | |
const CompoundWidget({Key key, this.onChanged}) : super(key: key); | |
@override | |
_CompoundWidgetState createState() => _CompoundWidgetState(); | |
} | |
class _CompoundWidgetState extends State<CompoundWidget> { | |
int _counter = 0; | |
Function _onChanged = (value) {}; | |
@override | |
Widget build(BuildContext context) { | |
return Row( | |
mainAxisSize: MainAxisSize.min, | |
mainAxisAlignment: MainAxisAlignment.spaceBetween, | |
children: [ | |
FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_counter--; | |
}); | |
widget.onChanged(_counter); | |
}, | |
child: Text( | |
'-', | |
style: TextStyle(color: Colors.white, fontSize: 24), | |
), | |
), | |
SizedBox( | |
width: 10, | |
), | |
Text('$_counter', style: TextStyle(fontSize: 24)), | |
SizedBox( | |
width: 10, | |
), | |
FloatingActionButton( | |
onPressed: () { | |
setState(() { | |
_counter++; | |
}); | |
widget.onChanged(_counter); | |
}, | |
child: Text( | |
'+', | |
style: TextStyle(color: Colors.white, fontSize: 24), | |
), | |
), | |
], | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment