add structure

This commit is contained in:
2020-05-29 07:45:27 +06:30
parent 4c851d9971
commit bad27ba5c4
272 changed files with 36065 additions and 174 deletions

227
lib/pages/pd/pd_form.dart Normal file
View File

@@ -0,0 +1,227 @@
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/log_model.dart';
import 'package:fcs/model/main_model.dart';
import 'package:fcs/model/pd_model.dart';
import 'package:fcs/theme/theme.dart';
import 'package:fcs/vo/pd.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';
import '../util.dart';
import 'pd_item.dart';
class PDForm extends StatefulWidget {
final PD pd;
const PDForm({Key key, this.pd}) : super(key: key);
@override
_PDFormState createState() => _PDFormState();
}
class _PDFormState extends State<PDForm> {
TextEditingController _date = new TextEditingController();
TextEditingController _userName = new TextEditingController();
PD pd = PD();
bool _isLoading = false;
bool isNew = true;
@override
void initState() {
super.initState();
if (widget.pd != null) {
_userName.text = widget.pd.userName;
} else {
var mainModel = Provider.of<MainModel>(context, listen: false);
_userName.text = mainModel.user.name;
}
_load();
}
_load() async {
if (widget.pd != null) {
this.pd = widget.pd;
_date.text = DateFormat('dd MMM yyyy hh:mm a').format(widget.pd.date);
isNew = false;
Provider.of<PDModel>(context, listen: false).loadPDLines(pd).then((_pd) {
setState(() {
this.pd = _pd;
});
});
}
}
@override
Widget build(BuildContext context) {
var languageModel = Provider.of<LanguageModel>(context);
final _formKey = GlobalKey<FormState>();
final dateBox = Container(
padding: EdgeInsets.only(left: 20, right: 15),
child: TextFormField(
controller: _date,
enabled: false,
cursorColor: primaryColor,
style: textStyle,
decoration: new InputDecoration(
labelText: AppTranslations.of(context).text("pd.date"),
labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
icon: Icon(
Icons.date_range,
color: primaryColor,
size: 23,
)),
));
final nameBox = Container(
padding: EdgeInsets.only(left: 20, right: 15),
child: TextFormField(
controller: _userName,
autofocus: false,
readOnly: true,
style: textStyle,
decoration: new InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
icon: Icon(
Icons.person,
color: primaryColor,
size: 25,
)),
));
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text(
AppTranslations.of(context).text('pd'),
style: languageModel.isEng
? TextStyle()
: TextStyle(fontFamily: 'MyanmarUnicode'),
),
actions: <Widget>[
isNew
? IconButton(
icon: Icon(Icons.send),
onPressed: () {
if (!_formKey.currentState.validate()) return;
showConfirmDialog(context, "pd.confirm", () {
_submit();
});
},
)
: Container()
],
),
floatingActionButton: isNew
? FloatingActionButton(
backgroundColor: primaryColor,
child: Icon(Icons.add),
onPressed: () async {
final PDLine pdLine = await Navigator.push<PDLine>(
context,
MaterialPageRoute(builder: (context) => PDItem()),
);
_save(pdLine);
},
)
: null,
body: Form(
key: _formKey,
child: ListView(
children: <Widget>[
isNew ? Container() : dateBox,
nameBox,
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: MyDataTable(
columns: [
MyDataColumn(
label: LocalText(context, "pd.product")),
MyDataColumn(
label: LocalText(context, "pd.storage"),
),
MyDataColumn(
label: LocalText(context, "pd.quantity")),
],
rows: getProductRow(pd),
),
),
],
),
)),
);
}
List<MyDataRow> getProductRow(PD pd) {
return pd.pdLines.map((p) {
return MyDataRow(
onSelectChanged: (bool selected) async {
if (!isNew) return;
var pdLine = await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PDItem(
pdLine: p,
)),
);
_save(pdLine);
},
cells: [
MyDataCell(
new Text(
p.productName,
style: textStyle,
),
),
MyDataCell(
new Text(p.storageName, style: textStyle),
),
MyDataCell(
new Text(p.quantity.toString(), style: textStyle),
),
],
);
}).toList();
}
_save(PDLine pdLine) {
if (pdLine == null) return;
if (pdLine.action == "create") {
if (pd.pdLines.contains(pdLine)) {
showMsgDialog(context, "Error", "Duplicate line");
return;
}
pd.pdLines.add(pdLine);
} else if (pdLine.action == "delete") {
pd.pdLines.remove(pdLine);
}
}
_submit() async {
if (pd.pdLines.length == 0) {
showMsgDialog(context, "Error", "No product line");
return;
}
setState(() {
_isLoading = true;
});
try {
PDModel pdModel = Provider.of<PDModel>(context);
await pdModel.createPD(pd);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
}

223
lib/pages/pd/pd_item.dart Normal file
View File

@@ -0,0 +1,223 @@
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/model/product_model.dart';
import 'package:fcs/model/storage_model.dart';
import 'package:fcs/theme/theme.dart';
import 'package:fcs/vo/pd.dart';
import 'package:fcs/vo/product.dart';
import 'package:fcs/vo/storage.dart';
import 'package:fcs/widget/localization/app_translations.dart';
import 'package:fcs/widget/progress.dart';
class PDItem extends StatefulWidget {
final PDLine pdLine;
const PDItem({Key key, this.pdLine}) : super(key: key);
@override
_PDItemState createState() => _PDItemState();
}
class _PDItemState extends State<PDItem> {
final _formKey = GlobalKey<FormState>();
bool _isLoading = false;
String currentStorageID;
String currentProductID;
TextEditingController _quantity = new TextEditingController();
PDLine pdLine = PDLine();
@override
void initState() {
super.initState();
if (widget.pdLine != null) {
this._quantity.text = widget.pdLine.quantity.toString();
this.currentProductID = widget.pdLine.productID;
this.currentStorageID = widget.pdLine.storageID;
this.pdLine = widget.pdLine;
this.pdLine.action = "update";
} else {
this.pdLine.action = "create";
}
}
Widget showInventoryList(BuildContext context, StorageModel storageModel) {
return Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Image.asset(
"assets/inventory.png",
color: primaryColor,
width: 25,
),
SizedBox(
width: 20,
),
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 quantityBox = Container(
padding: EdgeInsets.only(top: 10),
child: TextFormField(
controller: _quantity,
keyboardType: TextInputType.number,
autofocus: false,
cursorColor: primaryColor,
decoration: new InputDecoration(
labelText: AppTranslations.of(context).text("pd.quantity"),
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("pd.form.quan");
}
return null;
},
),
);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text(
AppTranslations.of(context).text('pd.product.title'),
style: languageModel.isEng
? TextStyle()
: TextStyle(fontFamily: 'MyanmarUnicode'),
),
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: 20.0),
children: <Widget>[
quantityBox,
showInventoryList(context, storageModel),
showProducts(context, productModel)
],
),
)),
);
}
_save() {
if (currentProductID == null || currentStorageID == null) return;
this.pdLine.storageID = currentStorageID;
var storageName =
Provider.of<StorageModel>(context).getStorageName(currentStorageID);
this.pdLine.storageName = storageName;
this.pdLine.productID = currentProductID;
var productName =
Provider.of<ProductModel>(context).getProductName(currentProductID);
this.pdLine.productName = productName;
this.pdLine.quantity = int.parse(_quantity.text);
Navigator.pop<PDLine>(context, this.pdLine);
}
_delete() {
this.pdLine.action = "delete";
Navigator.pop<PDLine>(context, this.pdLine);
}
}

187
lib/pages/pd/pd_list.dart Normal file
View File

@@ -0,0 +1,187 @@
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/pd_model.dart';
import 'package:fcs/pages/pd/pd_form.dart';
import 'package:fcs/theme/theme.dart';
import 'package:fcs/widget/localization/app_translations.dart';
import 'package:fcs/widget/progress.dart';
class PDList extends StatefulWidget {
@override
_PDListState createState() => _PDListState();
}
class _PDListState extends State<PDList> {
final double dotSize = 15.0;
DateTime _selectedDate = DateTime.now();
int _dateIndex = 0;
bool _isLoading = false;
@override
void initState() {
super.initState();
var pdModel = Provider.of<PDModel>(context, listen: false);
// pdModel.loadPDs();
_selectedDate = pdModel.selectedDate;
_dateIndex = pdModel.dateIndex;
}
Future<Null> _selectDate(BuildContext context) async {
var pdModel = Provider.of<PDModel>(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._dateIndex = pickedDate == currentDate ? 0 : 1;
setState(() {
_selectedDate = picked;
pdModel.filterDate(_selectedDate, _dateIndex);
});
}
}
@override
Widget build(BuildContext context) {
var pdModel = Provider.of<PDModel>(context);
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
backgroundColor: primaryColor,
title: Text(
AppTranslations.of(context).text('pd.title'),
style: Provider.of<LanguageModel>(context).isEng
? TextStyle()
: TextStyle(fontFamily: 'MyanmarUnicode'),
),
actions: <Widget>[
InkWell(
child: Container(
padding: EdgeInsets.only(right: 15, top: 15),
child: Stack(
children: <Widget>[
Image.asset(
"assets/date_filter.png",
color: Colors.white,
width: 25,
),
_dateIndex == 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) => PDForm()),
);
},
),
body: new ListView.builder(
padding: EdgeInsets.only(left: 10, right: 10, top: 15),
shrinkWrap: true,
itemCount: pdModel.pds.length,
itemBuilder: (BuildContext context, int index) {
return InkWell(
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => PDForm(
pd: pdModel.pds[index],
)),
);
},
child: Card(
elevation: 10,
color: Colors.white,
child: Row(
children: <Widget>[
new Padding(
padding: EdgeInsets.all(10),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Image.asset(
"assets/pdo.png",
width: 30,
color: primaryColor,
)),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: new Text(
pdModel.pds[index].date == null
? ""
: DateFormat('dd MMM yyyy')
.format(pdModel.pds[index].date),
style: textStyle),
),
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: new Text(
pdModel.pds[index].pdNumber == null
? ''
: pdModel.pds[index].pdNumber,
style: new TextStyle(
fontSize: 12.0, color: Colors.grey),
),
),
],
),
SizedBox(
height: 15,
)
],
),
),
);
}),
),
);
}
}