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);
|
||||
}
|
||||
}
|
||||
166
lib/pages/storage/inventory_take.dart
Normal file
166
lib/pages/storage/inventory_take.dart
Normal file
@@ -0,0 +1,166 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/storage_model.dart';
|
||||
import 'package:fcs/pages/storage/inventory_item.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/inventory_line.dart';
|
||||
import 'package:fcs/vo/inventory_taking.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/my_data_table.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
class TakeInventory extends StatefulWidget {
|
||||
@override
|
||||
_TakeInventoryState createState() => _TakeInventoryState();
|
||||
}
|
||||
|
||||
class _TakeInventoryState extends State<TakeInventory> {
|
||||
InventoryTaking inventoryTaking = InventoryTaking();
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
var _storages = Provider.of<StorageModel>(context, listen: false).storages;
|
||||
_storages.forEach((s) {
|
||||
s.products.forEach((p) {
|
||||
inventoryTaking.inventoryLines.add(InventoryLine(
|
||||
productID: p.id,
|
||||
productName: p.name,
|
||||
storageID: p.storageID,
|
||||
storageName: p.storageName,
|
||||
oldQty: p.quantity,
|
||||
quantity: p.quantity));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
'inventory.take',
|
||||
fontSize: 20,
|
||||
color: Colors.white,
|
||||
),
|
||||
actions: <Widget>[
|
||||
IconButton(
|
||||
icon: Icon(Icons.send),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "inventory.confirm", () {
|
||||
_submit();
|
||||
});
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: primaryColor,
|
||||
child: Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
final InventoryLine inventoryLine =
|
||||
await Navigator.push<InventoryLine>(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => InventoryItem()),
|
||||
);
|
||||
_save(inventoryLine);
|
||||
},
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
scrollDirection: Axis.vertical,
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "inventory.product")),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "inventory.storage")),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "inventory.old.qty"),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(context, "inventory.new.qty"),
|
||||
),
|
||||
],
|
||||
rows: getInventoryTable(inventoryTaking.inventoryLines),
|
||||
),
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
List<MyDataRow> getInventoryTable(List<InventoryLine> invLines) {
|
||||
return invLines.map((p) {
|
||||
return MyDataRow(
|
||||
onSelectChanged: (bool selected) async {
|
||||
var inventoryLine = await Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => InventoryItem(
|
||||
inventoryLine: p,
|
||||
)),
|
||||
);
|
||||
_save(inventoryLine);
|
||||
},
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
p.productName,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.storageName.toString(), style: textStyle),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.oldQty.toString(), style: textStyle),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.quantity.toString(), style: textStyle),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_save(InventoryLine inventoryLine) {
|
||||
if (inventoryLine == null) return;
|
||||
if (inventoryLine.action == "create") {
|
||||
if (inventoryTaking.inventoryLines.contains(inventoryLine)) {
|
||||
showMsgDialog(context, "Error", "Duplicate line");
|
||||
return;
|
||||
}
|
||||
inventoryTaking.inventoryLines.add(inventoryLine);
|
||||
} else if (inventoryLine.action == "delete") {
|
||||
inventoryTaking.inventoryLines.remove(inventoryLine);
|
||||
}
|
||||
}
|
||||
|
||||
_submit() async {
|
||||
if (inventoryTaking.inventoryLines.length == 0) {
|
||||
showMsgDialog(context, "Error", "No inventory line");
|
||||
return;
|
||||
}
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
StorageModel storageModel = Provider.of<StorageModel>(context);
|
||||
await storageModel.createInventoryTaking(inventoryTaking);
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
212
lib/pages/storage/inventory_taking_list.dart
Normal file
212
lib/pages/storage/inventory_taking_list.dart
Normal file
@@ -0,0 +1,212 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/storage_model.dart';
|
||||
import 'package:fcs/pages/storage/inventory_take.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/inventory_taking.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
import 'package:fcs/widget/my_data_table.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
class InventoryTakingList extends StatefulWidget {
|
||||
@override
|
||||
_InventoryTakingListState createState() => _InventoryTakingListState();
|
||||
}
|
||||
|
||||
class _InventoryTakingListState extends State<InventoryTakingList> {
|
||||
DateTime _selectedDate = DateTime.now();
|
||||
int _selectedIndex = 0;
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
var storageModel = Provider.of<StorageModel>(context, listen: false);
|
||||
_selectedIndex = storageModel.selectedIndex;
|
||||
_selectedDate = storageModel.selectedDate;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<Null> _selectDate(BuildContext context) async {
|
||||
StorageModel storageModel = Provider.of<StorageModel>(context);
|
||||
|
||||
final DateTime picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedDate,
|
||||
firstDate: DateTime(2015, 8),
|
||||
lastDate: DateTime(2101),
|
||||
builder: (BuildContext context, Widget child) {
|
||||
return Theme(
|
||||
data: ThemeData.light().copyWith(
|
||||
primaryColor: primaryColor, //Head background
|
||||
accentColor: secondaryColor, //selection color
|
||||
dialogBackgroundColor: Colors.white, //Background color
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
);
|
||||
if (picked != null) {
|
||||
var pickedDate = new DateTime(picked.year, picked.month, picked.day);
|
||||
var currentDate = new DateTime(
|
||||
DateTime.now().year, DateTime.now().month, DateTime.now().day);
|
||||
this._selectedIndex = pickedDate == currentDate ? 0 : 1;
|
||||
setState(() {
|
||||
_selectedDate = picked;
|
||||
storageModel.filterDate(_selectedDate, _selectedIndex);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
StorageModel storageModel = Provider.of<StorageModel>(context);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("inventory.takings"),
|
||||
style: Provider.of<LanguageModel>(context).isEng
|
||||
? TextStyle(fontSize: 18)
|
||||
: TextStyle(fontSize: 18, fontFamily: 'MyanmarUnicode')),
|
||||
actions: <Widget>[
|
||||
InkWell(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(right: 15, top: 20),
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
Image.asset(
|
||||
"assets/date_filter.png",
|
||||
color: Colors.white,
|
||||
width: 25,
|
||||
),
|
||||
_selectedIndex == 0
|
||||
? Container()
|
||||
: Positioned(
|
||||
bottom: 15,
|
||||
right: 10,
|
||||
child: Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: new BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: secondaryColor,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
onTap: () => _selectDate(context),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: primaryColor,
|
||||
child: Icon(Icons.add),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => TakeInventory()),
|
||||
);
|
||||
},
|
||||
),
|
||||
body: new ListView.builder(
|
||||
padding: EdgeInsets.only(left: 10, right: 10, top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: storageModel.inventoryTakings.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Card(
|
||||
elevation: 8,
|
||||
child: ExpansionTile(
|
||||
onExpansionChanged: (e) => _onExpend(
|
||||
context, e, storageModel.inventoryTakings[index]),
|
||||
title: ListTile(
|
||||
leading: Material(
|
||||
color: primaryColor,
|
||||
shape: CircleBorder(),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
child: Icon(Icons.note, color: Colors.white))),
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(storageModel.inventoryTakings[index].userName,
|
||||
style: textStyle),
|
||||
),
|
||||
subtitle: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text(
|
||||
DateFormat('dd MMM yyyy – hh:mm a').format(
|
||||
storageModel.inventoryTakings[index].dateTime),
|
||||
style: subTitleStyle),
|
||||
),
|
||||
),
|
||||
children: <Widget>[
|
||||
storageModel.inventoryTakings[index].linesLoaded
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columnSpacing: 50,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context, "inventory.product")),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context, "inventory.storage")),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context, "inventory.quantity")),
|
||||
],
|
||||
rows: getInventoryTable(
|
||||
storageModel.inventoryTakings[index]),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container(child: Text("Loading..."))
|
||||
],
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<MyDataRow> getInventoryTable(InventoryTaking inventoryTaking) {
|
||||
return inventoryTaking.inventoryLines.map((p) {
|
||||
return MyDataRow(
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
p.productName,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.storageName.toString(), style: textStyle),
|
||||
),
|
||||
MyDataCell(
|
||||
new Text(p.quantity.toString(), style: textStyle),
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_onExpend(BuildContext context, expended, InventoryTaking inventoryTaking) {
|
||||
if (!expended) return;
|
||||
StorageModel storageModel = Provider.of<StorageModel>(context);
|
||||
storageModel.loadInventoryLines(inventoryTaking);
|
||||
}
|
||||
}
|
||||
155
lib/pages/storage/storage_addition.dart
Normal file
155
lib/pages/storage/storage_addition.dart
Normal file
@@ -0,0 +1,155 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/language_model.dart';
|
||||
import 'package:fcs/model/storage_model.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/theme/theme.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 StorageAddition extends StatefulWidget {
|
||||
final Storage storage;
|
||||
|
||||
const StorageAddition({Key key, this.storage}) : super(key: key);
|
||||
@override
|
||||
_StorageAdditionState createState() => _StorageAdditionState();
|
||||
}
|
||||
|
||||
class _StorageAdditionState extends State<StorageAddition> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
TextEditingController nameController = new TextEditingController();
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.storage != null) {
|
||||
nameController.text = widget.storage.name;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var languageModel = Provider.of<LanguageModel>(context);
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(context, "storage.item.title",color: Colors.white,fontSize: 20,),
|
||||
actions: <Widget>[
|
||||
widget.storage == null
|
||||
? Container()
|
||||
: IconButton(
|
||||
icon: Icon(Icons.delete),
|
||||
onPressed: () {
|
||||
showConfirmDialog(context, "storage.delete_confirm", () {
|
||||
_delete(context);
|
||||
});
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: Icon(Icons.save),
|
||||
onPressed: () {
|
||||
_save(context);
|
||||
},
|
||||
)
|
||||
],
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: ListView(
|
||||
shrinkWrap: true,
|
||||
padding: EdgeInsets.only(left: 24.0, right: 24.0),
|
||||
children: <Widget>[
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: TextFormField(
|
||||
controller: nameController,
|
||||
autofocus: false,
|
||||
cursorColor: primaryColor,
|
||||
decoration: new InputDecoration(
|
||||
labelText: AppTranslations.of(context)
|
||||
.text("storage.name"),
|
||||
labelStyle:
|
||||
languageModel.isEng ? labelStyle : labelStyleMM,
|
||||
icon: Image.asset(
|
||||
"assets/inventory.png",
|
||||
color: primaryColor,
|
||||
width: 25,
|
||||
),
|
||||
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("storage.form.name");
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
void _save(BuildContext context) async {
|
||||
if (!_formKey.currentState.validate()) return;
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
if (widget.storage != null) {
|
||||
widget.storage.name = nameController.text;
|
||||
await Provider.of<StorageModel>(context, listen: false)
|
||||
.updateStorage(widget.storage);
|
||||
} else {
|
||||
await Provider.of<StorageModel>(context, listen: false)
|
||||
.createStorage(Storage(name: nameController.text));
|
||||
}
|
||||
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _delete(BuildContext context) async {
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
try {
|
||||
if (widget.storage != null) {
|
||||
await Provider.of<StorageModel>(context, listen: false)
|
||||
.deleteStorage(widget.storage.id);
|
||||
}
|
||||
Navigator.pop(context);
|
||||
} catch (e) {
|
||||
showMsgDialog(context, "Error", e.toString());
|
||||
} finally {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
191
lib/pages/storage/storage_list.dart
Normal file
191
lib/pages/storage/storage_list.dart
Normal file
@@ -0,0 +1,191 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/model/storage_model.dart';
|
||||
import 'package:fcs/pages/storage/storage_addition.dart';
|
||||
import 'package:fcs/theme/theme.dart';
|
||||
import 'package:fcs/vo/popup_menu.dart';
|
||||
import 'package:fcs/vo/storage.dart';
|
||||
import 'package:fcs/widget/local_text.dart';
|
||||
import 'package:fcs/widget/my_data_table.dart';
|
||||
import 'package:fcs/widget/number_cell.dart';
|
||||
import 'package:fcs/widget/popupmenu.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
import 'inventory_taking_list.dart';
|
||||
|
||||
class StorageList extends StatefulWidget {
|
||||
@override
|
||||
_StorageListState createState() => _StorageListState();
|
||||
}
|
||||
|
||||
class _StorageListState extends State<StorageList> {
|
||||
final double dotSize = 15.0;
|
||||
PopupMenu selectedChoices = storageMenus[0];
|
||||
bool _isLoading = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var storageModel = Provider.of<StorageModel>(context);
|
||||
|
||||
void _select(PopupMenu choice) async {
|
||||
selectedChoices = choice;
|
||||
if (choice.status == "Inventory Takings") {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => InventoryTakingList()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
backgroundColor: primaryColor,
|
||||
title: LocalText(
|
||||
context,
|
||||
"storage.title",
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
),
|
||||
actions: <Widget>[
|
||||
PopupMenuButton<PopupMenu>(
|
||||
elevation: 3.2,
|
||||
onSelected: _select,
|
||||
itemBuilder: (BuildContext context) {
|
||||
return storageMenus.map((PopupMenu choice) {
|
||||
return PopupMenuItem<PopupMenu>(
|
||||
value: choice,
|
||||
child: Text(choice.status),
|
||||
);
|
||||
}).toList();
|
||||
})
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
backgroundColor: primaryColor,
|
||||
child: Icon(Icons.add),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => StorageAddition()),
|
||||
);
|
||||
},
|
||||
),
|
||||
body: new ListView.builder(
|
||||
padding: EdgeInsets.only(left: 10, right: 10, top: 15),
|
||||
shrinkWrap: true,
|
||||
itemCount: storageModel.storages.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return Card(
|
||||
elevation: 10,
|
||||
color: Colors.white,
|
||||
child: Theme(
|
||||
data: ThemeData(accentColor: Colors.grey),
|
||||
child: ExpansionTile(
|
||||
onExpansionChanged: (e) =>
|
||||
_onExpend(context, e, storageModel.storages[index]),
|
||||
title: Row(
|
||||
children: <Widget>[
|
||||
new Row(
|
||||
children: <Widget>[
|
||||
new Padding(
|
||||
padding: new EdgeInsets.symmetric(
|
||||
horizontal: 10.0 - dotSize / 2),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(10.0),
|
||||
child: Image.asset(
|
||||
"assets/inventory.png",
|
||||
width: 40,
|
||||
color: primaryColor,
|
||||
)),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: new Text(
|
||||
storageModel.storages[index].name == null
|
||||
? ""
|
||||
: storageModel.storages[index].name,
|
||||
style: textStyle),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 8.0),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => StorageAddition(
|
||||
storage:
|
||||
storageModel.storages[index])),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 15,
|
||||
)
|
||||
],
|
||||
),
|
||||
children: <Widget>[
|
||||
storageModel.storages[index].productsLoaded
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: MyDataTable(
|
||||
headingRowHeight: 40,
|
||||
columnSpacing: 50,
|
||||
columns: [
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context, "inventory.product"),
|
||||
),
|
||||
MyDataColumn(
|
||||
label: LocalText(
|
||||
context, "inventory.quantity"),
|
||||
),
|
||||
],
|
||||
rows: getProductRow(
|
||||
storageModel.storages[index]),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text("Loading..."),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<MyDataRow> getProductRow(Storage storage) {
|
||||
return storage.products.map((p) {
|
||||
return MyDataRow(
|
||||
cells: [
|
||||
MyDataCell(
|
||||
new Text(
|
||||
p.name,
|
||||
style: textStyle,
|
||||
),
|
||||
),
|
||||
MyDataCell(
|
||||
NumberCell(p.quantity)
|
||||
),
|
||||
],
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
_onExpend(BuildContext context, expended, Storage storage) {
|
||||
if (!expended) return;
|
||||
storage.productsLoaded = false;
|
||||
StorageModel storageModel = Provider.of<StorageModel>(context);
|
||||
storageModel.loadProducts(storage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user