add structure
This commit is contained in:
249
lib/pages/storage/inventory_item.dart
Normal file
249
lib/pages/storage/inventory_item.dart
Normal file
@@ -0,0 +1,249 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.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/model/product_model.dart';
|
||||
import 'package:fcs/model/storage_model.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/inventory_line.dart';
|
||||
import 'package:fcs/vo/product.dart';
|
||||
import 'package:fcs/vo/storage.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
class InventoryItem extends StatefulWidget {
|
||||
final InventoryLine inventoryLine;
|
||||
|
||||
const InventoryItem({Key key, this.inventoryLine}) : super(key: key);
|
||||
|
||||
@override
|
||||
_InventoryItemState createState() => _InventoryItemState();
|
||||
}
|
||||
|
||||
class _InventoryItemState extends State<InventoryItem> {
|
||||
InventoryLine inventoryLine = new InventoryLine();
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
bool _isLoading = false;
|
||||
String currentStorageID, currentProductID;
|
||||
TextEditingController _volumeController = new TextEditingController();
|
||||
TextEditingController _oldVolume = new TextEditingController();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.inventoryLine != null) {
|
||||
this.inventoryLine = widget.inventoryLine;
|
||||
this.inventoryLine.action = "update";
|
||||
_oldVolume.text = this.inventoryLine.oldQty.toString();
|
||||
} else {
|
||||
this.inventoryLine.action = "create";
|
||||
}
|
||||
|
||||
_volumeController.text =
|
||||
inventoryLine.quantity == null ? "" : inventoryLine.quantity.toString();
|
||||
this.currentStorageID = inventoryLine.storageID;
|
||||
this.currentProductID = inventoryLine.productID;
|
||||
}
|
||||
|
||||
Widget showStorageList(BuildContext context, StorageModel storageModel) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
"assets/inventory.png",
|
||||
color: primaryColor,
|
||||
width: 25,
|
||||
),
|
||||
SizedBox(
|
||||
width: 18,
|
||||
),
|
||||
new Flexible(
|
||||
child: Container(
|
||||
width: 170.0,
|
||||
child: DropdownButton<String>(
|
||||
value: currentStorageID,
|
||||
isExpanded: true,
|
||||
hint: Text(
|
||||
'Select Storage',
|
||||
style: labelStyle,
|
||||
),
|
||||
onChanged: changedDropDownItem,
|
||||
items: storageModel.storages
|
||||
.map<DropdownMenuItem<String>>((Storage storage) {
|
||||
return new DropdownMenuItem<String>(
|
||||
value: storage.id,
|
||||
child: new Text(storage.name, style: textStyle),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void changedDropDownItem(selected) {
|
||||
setState(() {
|
||||
currentStorageID = selected;
|
||||
});
|
||||
}
|
||||
|
||||
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) {
|
||||
var storageModel = Provider.of<StorageModel>(context);
|
||||
var productModel = Provider.of<ProductModel>(context);
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
|
||||
final oldVolumeBox = Container(
|
||||
padding: EdgeInsets.only(left: 5, top: 15, bottom: 10),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
LocalText(context, "inventory.old.qty"),
|
||||
Container(
|
||||
padding: EdgeInsets.only(left: 20),
|
||||
child: Text(
|
||||
_oldVolume.text,
|
||||
style: textStyle,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
'inventory.item',
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
_delete();
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.save),
|
||||
onPressed: () {
|
||||
if (!_formKey.currentState.validate()) return;
|
||||
_save();
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
||||
children: <Widget>[
|
||||
widget.inventoryLine == null ? Container() : oldVolumeBox,
|
||||
showStorageList(context, storageModel),
|
||||
showProducts(context, productModel),
|
||||
Container(
|
||||
child: TextFormField(
|
||||
keyboardType: TextInputType.number,
|
||||
controller: _volumeController,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
decoration: new InputDecoration(
|
||||
labelText:
|
||||
AppTranslations.of(context).text("inventory.new.qty"),
|
||||
labelStyle:
|
||||
languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Icon(
|
||||
FontAwesomeIcons.sortNumericUpAlt,
|
||||
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 AppTranslations.of(context)
|
||||
.text("inventory.form.qty");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
_save() {
|
||||
if (currentProductID == null || currentStorageID == null) return;
|
||||
this.inventoryLine.storageID = currentStorageID;
|
||||
var storageName =
|
||||
Provider.of<StorageModel>(context).getStorageName(currentStorageID);
|
||||
this.inventoryLine.storageName = storageName;
|
||||
this.inventoryLine.productID = currentProductID;
|
||||
var productName =
|
||||
Provider.of<ProductModel>(context).getProductName(currentProductID);
|
||||
this.inventoryLine.productName = productName;
|
||||
this.inventoryLine.quantity = int.parse(_volumeController.text);
|
||||
Navigator.pop<InventoryLine>(context, this.inventoryLine);
|
||||
}
|
||||
|
||||
_delete() {
|
||||
this.inventoryLine.action = "delete";
|
||||
Navigator.pop<InventoryLine>(context, this.inventoryLine);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user