Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AddCartButton extends StatefulWidget {
- @override
- State<StatefulWidget> createState() {
- return AddCartButtonState();
- }
- }
- class AddCartButtonState extends State<AddCartButton>{
- TextEditingController myController = TextEditingController();
- bool isValid = false;
- @override
- Widget build(BuildContext context) {
- void _addToCart(){
- showDialog(
- context: context,
- builder: (BuildContext context) {
- return AlertDialog(
- title: Text("QUANTITY"),
- content: Column(
- children: <Widget>[
- TextFormField(
- controller: myController,
- decoration: new InputDecoration(labelText: "quantity"),
- keyboardType: TextInputType.numberWithOptions(decimal: true),
- inputFormatters: <TextInputFormatter>[],
- autovalidate: true,
- validator: (value) {
- if (value.isEmpty) {
- isValid = false;
- return "the quantity cannot be empty";
- } else if (double.tryParse(value) == null) {
- isValid = false;
- return "the quantity must be valid number";
- } else {
- isValid = true;
- return null;
- }
- }
- )
- ],
- ),
- actions: <Widget>[
- FlatButton(
- disabledTextColor: Colors.grey,
- child: Text("add"),
- onPressed: isValid ? () { print("is valid"); }: null
- )
- ],
- );
- },
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement