import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:provider/provider.dart'; import 'package:fcs/model/language_model.dart'; import 'package:fcs/pages/util.dart'; import 'package:fcs/theme/theme.dart'; import 'package:fcs/vo/do.dart'; import 'package:fcs/widget/local_text.dart'; import 'package:fcs/widget/localization/app_translations.dart'; import 'package:fcs/widget/progress.dart'; class DOProductItem extends StatefulWidget { final DOLine doLine; const DOProductItem({Key key, this.doLine}) : super(key: key); @override _DOProductItemState createState() => _DOProductItemState(); } class _DOProductItemState extends State { final _formKey = GlobalKey(); TextEditingController _doQty = new TextEditingController(); DOLine doLine; bool _isLoading = false; @override void initState() { super.initState(); if (widget.doLine != null) { doLine = widget.doLine; _doQty.text = widget.doLine.qty.toString(); } } @override Widget build(BuildContext context) { var languageModel = Provider.of(context); return LocalProgress( inAsyncCall: _isLoading, child: AlertDialog( title: Center( child: Text( AppTranslations.of(context).text("do_qty"), style: TextStyle( color: primaryColor, fontWeight: FontWeight.bold, fontSize: 20), )), content: Form( key: _formKey, child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ new Expanded( child: new TextFormField( keyboardType: TextInputType.number, autofocus: true, controller: _doQty, style: TextStyle(fontWeight: FontWeight.bold, fontSize: 20), cursorColor: primaryColor, decoration: new InputDecoration( fillColor: primaryColor, icon: Icon( FontAwesomeIcons.sortNumericUpAlt, color: primaryColor, ), focusedBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors.grey, width: 1.0)), ), validator: (value) { if (value.isEmpty) { return AppTranslations.of(context).text("do.form.volume"); } return null; }, )) ], ), ), actions: [ FlatButton( child: LocalText( context, 'do.cancel', color: secondaryColor, ), onPressed: () { _doQty.clear(); Navigator.of(context).pop(); }), FlatButton( color: primaryColor, child: LocalText( context, 'do.enter', color: Colors.white, fontWeight: FontWeight.bold, ), onPressed: () async { if (!_formKey.currentState.validate()) return; _save(); }) ], ), ); } _save() { setState(() { _isLoading = true; }); try { var qty = int.parse(_doQty.text); if (qty < 0) throw Exception("invalid number, must be zero or greater than zero"); // if (qty > doLine.poLine.balanceQty) // throw Exception( // "invalid number, must be less than or equal to PO balance qty"); this.doLine.qty = qty; Navigator.pop(context, this.doLine); } catch (e) { showMsgDialog(context, "Error", e.toString()); } finally { setState(() { _isLoading = false; }); } } _delete() { this.doLine.action = "delete"; this.doLine.qty = 0; Navigator.pop(context, this.doLine); } }