add packages, receiving & processing

This commit is contained in:
Sai Naw Wun
2020-10-12 03:34:05 +06:30
parent 32e6be2abd
commit b13dc69161
36 changed files with 1110 additions and 668 deletions

View File

@@ -20,22 +20,38 @@ import 'package:provider/provider.dart';
typedef void FindCallBack();
class ReceivingNew extends StatefulWidget {
const ReceivingNew();
class ReceivingEditor extends StatefulWidget {
final Package package;
const ReceivingEditor({this.package});
@override
_ReceivingNewState createState() => _ReceivingNewState();
_ReceivingEditorState createState() => _ReceivingEditorState();
}
class _ReceivingNewState extends State<ReceivingNew> {
class _ReceivingEditorState extends State<ReceivingEditor> {
Package package = Package();
bool _isLoading = false;
bool _isNew;
User user;
TextEditingController _transcationIDCtl = new TextEditingController();
TextEditingController _trackingIDCtl = new TextEditingController();
TextEditingController _remarkCtl = new TextEditingController();
MultiImgController _multiImgController = MultiImgController();
@override
void initState() {
super.initState();
_isNew = widget.package == null;
if (!_isNew) {
package = widget.package;
_trackingIDCtl.text = package.trackingID;
_remarkCtl.text = package.remark;
_multiImgController.setImageUrls = package.photoUrls;
user = User(
fcsID: package.fcsID,
name: package.userName,
phoneNumber: package.phoneNumber);
} else {
package = new Package();
}
}
@override
@@ -66,7 +82,7 @@ class _ReceivingNewState extends State<ReceivingNew> {
Expanded(
child: InputText(
labelTextKey: "receiving.tracking.id",
controller: _transcationIDCtl,
controller: _trackingIDCtl,
)),
IconButton(
icon: Icon(MaterialCommunityIcons.barcode_scan,
@@ -99,7 +115,13 @@ class _ReceivingNewState extends State<ReceivingNew> {
final createButton = fcsButton(
context,
getLocalString(context, 'receiving.create_btn'),
callack: _create,
callack: _save,
);
final updateButton = fcsButton(
context,
getLocalString(context, 'receiving.update_btn'),
callack: _save,
);
return LocalProgress(
@@ -115,7 +137,7 @@ class _ReceivingNewState extends State<ReceivingNew> {
backgroundColor: Colors.white,
title: LocalText(
context,
"receiving.new",
_isNew ? "receiving.new" : "receiving.update",
fontSize: 20,
color: primaryColor,
),
@@ -139,7 +161,7 @@ class _ReceivingNewState extends State<ReceivingNew> {
SizedBox(
height: 20,
),
createButton,
_isNew ? createButton : updateButton,
SizedBox(
height: 10,
),
@@ -166,7 +188,7 @@ class _ReceivingNewState extends State<ReceivingNew> {
String barcode = await scanBarcode();
if (barcode != null) {
setState(() {
_transcationIDCtl.text = barcode;
_trackingIDCtl.text = barcode;
});
}
} catch (e) {
@@ -174,9 +196,8 @@ class _ReceivingNewState extends State<ReceivingNew> {
}
}
_create() async {
Package package = Package();
package.trackingID = _transcationIDCtl.text;
_save() async {
package.trackingID = _trackingIDCtl.text;
package.remark = _remarkCtl.text;
if (package.trackingID == null || package.trackingID == "") {
@@ -189,8 +210,17 @@ class _ReceivingNewState extends State<ReceivingNew> {
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
try {
await packageModel.createPackage(user, package,
_multiImgController.getAddedFile, _multiImgController.getDeletedUrl);
if (_isNew) {
await packageModel.createReceiving(
user, package, _multiImgController.getAddedFile);
} else {
package.id = widget.package.id;
await packageModel.updateReceiving(
user,
package,
_multiImgController.getAddedFile,
_multiImgController.getDeletedUrl);
}
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -18,6 +18,8 @@ import 'package:provider/provider.dart';
import 'package:timeline_list/timeline.dart';
import 'package:timeline_list/timeline_model.dart';
import 'receiving_editor.dart';
final DateFormat dateFormat = DateFormat("d MMM yyyy");
class ReceivingInfo extends StatefulWidget {
@@ -40,9 +42,9 @@ class _ReceivingInfoState extends State<ReceivingInfo> {
}
initPackage(Package package) {
multiImgController.setImageUrls = package.photoUrls;
setState(() {
_package = package;
multiImgController.setImageUrls = package.photoUrls;
});
}
@@ -89,18 +91,22 @@ class _ReceivingInfoState extends State<ReceivingInfo> {
backgroundColor: Colors.white,
title: LocalText(
context,
"package.info.title",
"receiving.info",
fontSize: 20,
color: primaryColor,
),
actions: <Widget>[
isCustomer
? Container()
: IconButton(
actions: isCustomer
? null
: <Widget>[
IconButton(
icon: Icon(Icons.delete, color: primaryColor),
onPressed: _delete,
),
IconButton(
icon: Icon(Icons.edit, color: primaryColor),
onPressed: _edit,
)
],
],
),
body: Card(
child: Column(
@@ -113,19 +119,9 @@ class _ReceivingInfoState extends State<ReceivingInfo> {
_package.userID != null ? customerNameBox : Container(),
_package.photoUrls.length == 0 ? Container() : img,
remarkBox,
ExpansionTile(
initiallyExpanded: true,
title: Text(
'Status',
style: TextStyle(
color: primaryColor, fontWeight: FontWeight.bold),
),
children: <Widget>[
StatusTree(
shipmentHistory: _package.shipmentHistory,
currentStatus: _package.currentStatus),
],
),
StatusTree(
shipmentHistory: _package.shipmentHistory,
currentStatus: _package.currentStatus),
SizedBox(
height: 20,
)
@@ -138,6 +134,19 @@ class _ReceivingInfoState extends State<ReceivingInfo> {
);
}
_edit() async {
await Navigator.push(
context,
BottomUpPageRoute(ReceivingEditor(
package: widget.package,
)),
);
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
var pkg = await packageModel.getPackage(widget.package.id);
initPackage(pkg);
}
_delete() {
showConfirmDialog(context, "receiving.delete.confirm", _deleteReceiving);
}
@@ -149,7 +158,7 @@ class _ReceivingInfoState extends State<ReceivingInfo> {
try {
PackageModel packageModel =
Provider.of<PackageModel>(context, listen: false);
await packageModel.deletePackage(_package);
await packageModel.deleteReceiving(_package);
Navigator.pop(context);
} catch (e) {
showMsgDialog(context, "Error", e.toString());

View File

@@ -12,7 +12,7 @@ import 'package:provider/provider.dart';
import 'receiving_info.dart';
import 'receiving_list_row.dart';
import 'receiving_new.dart';
import 'receiving_editor.dart';
class ReceivingList extends StatefulWidget {
@override
@@ -98,7 +98,7 @@ class _ReceivingListState extends State<ReceivingList> {
_newReceiving() {
Navigator.push(
context,
BottomUpPageRoute(ReceivingNew()),
BottomUpPageRoute(ReceivingEditor()),
);
}