2020-05-29 07:45:27 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import 'package:fcs/model/product_model.dart';
|
2020-08-30 21:26:37 +06:30
|
|
|
import 'package:fcs/fcs/common/theme.dart';
|
2020-05-29 07:45:27 +06:30
|
|
|
import 'package:fcs/vo/buyer.dart';
|
|
|
|
|
import 'package:fcs/vo/product.dart';
|
|
|
|
|
import 'package:fcs/widget/progress.dart';
|
|
|
|
|
|
|
|
|
|
class MyRegisterationItem extends StatefulWidget {
|
|
|
|
|
final BuyerProduct buyerProduct;
|
|
|
|
|
const MyRegisterationItem({Key key, this.buyerProduct}) : super(key: key);
|
|
|
|
|
@override
|
|
|
|
|
_MyRegisterationItemState createState() => _MyRegisterationItemState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _MyRegisterationItemState extends State<MyRegisterationItem> {
|
|
|
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
|
bool _isLoading = false;
|
|
|
|
|
TextEditingController _storage = new TextEditingController();
|
|
|
|
|
TextEditingController _sales = new TextEditingController();
|
|
|
|
|
String currentProductID;
|
|
|
|
|
BuyerProduct buyerProduct = BuyerProduct(action: "create");
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
if (widget.buyerProduct != null) {
|
|
|
|
|
buyerProduct = widget.buyerProduct;
|
|
|
|
|
buyerProduct.action = "update";
|
|
|
|
|
currentProductID = buyerProduct.productID;
|
|
|
|
|
_sales.text = buyerProduct.dailySaleQty.toString();
|
|
|
|
|
_storage.text = buyerProduct.storageCapacityQty.toString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Widget showProducts(BuildContext context, ProductModel productModel) {
|
|
|
|
|
return Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.max,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Icon(
|
|
|
|
|
FontAwesomeIcons.tag,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
size: 20,
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
width: 20,
|
|
|
|
|
),
|
|
|
|
|
new Flexible(
|
|
|
|
|
child: Container(
|
|
|
|
|
width: 170.0,
|
|
|
|
|
child: DropdownButton<String>(
|
|
|
|
|
value: currentProductID,
|
|
|
|
|
isExpanded: true,
|
|
|
|
|
hint: Text(
|
|
|
|
|
'Select Product',
|
|
|
|
|
style: labelStyle,
|
|
|
|
|
),
|
|
|
|
|
onChanged: changedProduct,
|
|
|
|
|
items: productModel.products
|
|
|
|
|
.map<DropdownMenuItem<String>>((Product product) {
|
|
|
|
|
return new DropdownMenuItem<String>(
|
|
|
|
|
value: product.id,
|
|
|
|
|
child: new Text(product.name, style: textStyle),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void changedProduct(selected) {
|
|
|
|
|
setState(() {
|
|
|
|
|
currentProductID = selected;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
ProductModel productModel = Provider.of<ProductModel>(context);
|
|
|
|
|
|
|
|
|
|
final volumeBox = Container(
|
|
|
|
|
padding: EdgeInsets.only(top: 10),
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _storage,
|
|
|
|
|
autofocus: false,
|
|
|
|
|
cursorColor: primaryColor,
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
decoration: new InputDecoration(
|
|
|
|
|
labelText: "Enter total storage capacity",
|
|
|
|
|
labelStyle: labelStyle,
|
|
|
|
|
icon: Image.asset(
|
|
|
|
|
"assets/volume.png",
|
|
|
|
|
width: 23,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
|
|
|
|
),
|
|
|
|
|
validator: (value) {
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
return "Please total storage capacity";
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
final amountBox = Container(
|
|
|
|
|
child: TextFormField(
|
|
|
|
|
controller: _sales,
|
|
|
|
|
autofocus: false,
|
|
|
|
|
cursorColor: primaryColor,
|
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
|
decoration: new InputDecoration(
|
|
|
|
|
labelText: "Enter daily sale quantity",
|
|
|
|
|
labelStyle: labelStyle,
|
|
|
|
|
icon: Image.asset(
|
|
|
|
|
"assets/sales.png",
|
|
|
|
|
width: 23,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
enabledBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
|
|
|
|
focusedBorder: UnderlineInputBorder(
|
|
|
|
|
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
|
|
|
|
),
|
|
|
|
|
validator: (value) {
|
|
|
|
|
if (value.isEmpty) {
|
|
|
|
|
return "Please enter daily sale quantity";
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
backgroundColor: primaryColor,
|
|
|
|
|
title: Text("Product registration"),
|
|
|
|
|
actions: <Widget>[
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.delete),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
buyerProduct.action = "delete";
|
|
|
|
|
Navigator.pop(context, buyerProduct);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.save),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
if (!_formKey.currentState.validate()) return;
|
|
|
|
|
_save();
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
body: Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Column(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
showProducts(context, productModel),
|
|
|
|
|
volumeBox,
|
|
|
|
|
amountBox,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_save() {
|
|
|
|
|
if (currentProductID == null) return;
|
|
|
|
|
this.buyerProduct.productID = currentProductID;
|
|
|
|
|
var productName =
|
|
|
|
|
Provider.of<ProductModel>(context).getProductName(currentProductID);
|
|
|
|
|
this.buyerProduct.productName = productName;
|
|
|
|
|
this.buyerProduct.storageCapacityQty = int.parse(_storage.text);
|
|
|
|
|
this.buyerProduct.dailySaleQty = int.parse(_sales.text);
|
|
|
|
|
Navigator.pop<BuyerProduct>(context, this.buyerProduct);
|
|
|
|
|
}
|
|
|
|
|
}
|