Skip to content

Instantly share code, notes, and snippets.

@agnamc9
Created September 3, 2020 11:58
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 agnamc9/761970ee202b352823cbc62047b52c9c to your computer and use it in GitHub Desktop.
Save agnamc9/761970ee202b352823cbc62047b52c9c to your computer and use it in GitHub Desktop.
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