2020-10-08 16:53:43 +06:30
|
|
|
import 'package:fcs/domain/entities/package.dart';
|
2020-12-01 19:02:21 +06:30
|
|
|
import 'package:fcs/domain/entities/processing.dart';
|
2020-10-12 03:34:05 +06:30
|
|
|
import 'package:fcs/domain/entities/user.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2020-10-12 03:34:05 +06:30
|
|
|
import 'package:fcs/pages/user_search/user_serach.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
2020-10-12 03:34:05 +06:30
|
|
|
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
2020-10-14 13:54:42 +06:30
|
|
|
import 'package:flutter/cupertino.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_icons/flutter_icons.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
import 'model/processing_model.dart';
|
|
|
|
|
import 'package_editor.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
class ProcesingEditor extends StatefulWidget {
|
|
|
|
|
final Processing processing;
|
|
|
|
|
const ProcesingEditor({this.processing});
|
2020-10-08 16:53:43 +06:30
|
|
|
@override
|
2020-12-01 19:02:21 +06:30
|
|
|
_ProcesingEditorState createState() => _ProcesingEditorState();
|
2020-10-08 16:53:43 +06:30
|
|
|
}
|
|
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
class _ProcesingEditorState extends State<ProcesingEditor> {
|
|
|
|
|
Processing processing = Processing();
|
2020-10-08 16:53:43 +06:30
|
|
|
bool _isLoading = false;
|
2020-12-01 19:02:21 +06:30
|
|
|
bool _isNew;
|
|
|
|
|
User user;
|
|
|
|
|
User shipper;
|
|
|
|
|
List<Package> packages = [];
|
2020-10-08 16:53:43 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2020-12-01 19:02:21 +06:30
|
|
|
_isNew = widget.processing == null;
|
|
|
|
|
if (!_isNew) {
|
|
|
|
|
processing = widget.processing;
|
|
|
|
|
user = User(
|
|
|
|
|
fcsID: processing.userID,
|
|
|
|
|
name: processing.userName,
|
|
|
|
|
phoneNumber: processing.userPhoneNumber);
|
|
|
|
|
shipper = User(
|
|
|
|
|
fcsID: processing.fcsID,
|
|
|
|
|
name: processing.shipperName,
|
|
|
|
|
phoneNumber: processing.shipperPhoneNumber);
|
|
|
|
|
packages = processing.packages;
|
|
|
|
|
}
|
2020-10-08 16:53:43 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2020-10-12 03:34:05 +06:30
|
|
|
var fcsIDBox = Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: DisplayText(
|
2020-12-01 19:02:21 +06:30
|
|
|
text: user != null ? user.fcsID : "",
|
2020-10-12 03:34:05 +06:30
|
|
|
labelTextKey: "processing.fcs.id",
|
|
|
|
|
icon: FcsIDIcon(),
|
|
|
|
|
)),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.search, color: primaryColor),
|
|
|
|
|
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
|
|
|
|
setState(() {
|
2020-12-01 19:02:21 +06:30
|
|
|
this.user = u;
|
2020-10-12 03:34:05 +06:30
|
|
|
});
|
|
|
|
|
})),
|
|
|
|
|
],
|
|
|
|
|
);
|
2020-12-01 19:02:21 +06:30
|
|
|
|
2020-10-12 03:34:05 +06:30
|
|
|
final phoneNumberBox = DisplayText(
|
2020-12-01 19:02:21 +06:30
|
|
|
text: user != null ? user.phoneNumber : "",
|
2020-10-12 03:34:05 +06:30
|
|
|
labelTextKey: "processing.phone",
|
2020-12-01 19:02:21 +06:30
|
|
|
maxLines: 2,
|
2020-10-12 03:34:05 +06:30
|
|
|
iconData: Icons.phone,
|
|
|
|
|
);
|
|
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
final namebox = DisplayText(
|
|
|
|
|
text: user != null ? user.name : "",
|
|
|
|
|
labelTextKey: "processing.consignee.name",
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
iconData: Icons.person,
|
2020-10-08 16:53:43 +06:30
|
|
|
);
|
2020-12-01 19:02:21 +06:30
|
|
|
|
|
|
|
|
final consigneeBox = Container(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
fcsIDBox,
|
|
|
|
|
phoneNumberBox,
|
|
|
|
|
namebox,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
var shipperIDBox = Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: DisplayText(
|
|
|
|
|
text: shipper != null ? shipper.fcsID : "",
|
|
|
|
|
labelTextKey: "processing.fcs.id",
|
|
|
|
|
icon: FcsIDIcon(),
|
|
|
|
|
)),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.search, color: primaryColor),
|
|
|
|
|
onPressed: () => searchUser(context, callbackUserSelect: (u) {
|
|
|
|
|
setState(() {
|
|
|
|
|
this.shipper = u;
|
|
|
|
|
});
|
|
|
|
|
})),
|
|
|
|
|
],
|
2020-10-08 16:53:43 +06:30
|
|
|
);
|
|
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
final shipperPhoneNumberBox = DisplayText(
|
|
|
|
|
text: shipper != null ? shipper.phoneNumber : "",
|
|
|
|
|
labelTextKey: "processing.phone",
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
iconData: Icons.phone,
|
2020-10-08 16:53:43 +06:30
|
|
|
);
|
2020-12-01 19:02:21 +06:30
|
|
|
|
|
|
|
|
final shipperNamebox = DisplayText(
|
|
|
|
|
text: shipper != null ? shipper.name : "",
|
|
|
|
|
labelTextKey: "processing.shipper.name",
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
iconData: Icons.person,
|
2020-10-08 16:53:43 +06:30
|
|
|
);
|
|
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
final shipperBox = Container(
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
shipperIDBox,
|
|
|
|
|
shipperPhoneNumberBox,
|
|
|
|
|
shipperNamebox,
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
2020-10-08 16:53:43 +06:30
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
final packageTitleBox = Container(
|
2020-10-12 03:34:05 +06:30
|
|
|
child: Row(
|
2020-12-01 19:02:21 +06:30
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
2020-10-12 03:34:05 +06:30
|
|
|
children: [
|
2020-12-01 19:02:21 +06:30
|
|
|
Text("Packages (${packages.length})"),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(
|
|
|
|
|
Icons.add_circle,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () async {
|
2020-12-02 20:55:00 +06:30
|
|
|
Package _package = await Navigator.push<Package>(
|
2020-12-01 19:02:21 +06:30
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(builder: (context) => PackageEditor()),
|
|
|
|
|
);
|
2020-12-02 20:55:00 +06:30
|
|
|
_addPackage(_package);
|
|
|
|
|
// _savePackage(_package);
|
2020-12-01 19:02:21 +06:30
|
|
|
}),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final createButton = fcsButton(
|
|
|
|
|
context,
|
|
|
|
|
getLocalString(context, 'processing.edit.complete.btn'),
|
|
|
|
|
callack: _save,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
|
|
|
|
icon:
|
|
|
|
|
new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
|
2020-12-04 17:28:21 +06:30
|
|
|
onPressed: () {
|
|
|
|
|
showConfirmDialog(context, "back.button_confirm", () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-12-01 19:02:21 +06:30
|
|
|
),
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
_isNew ? "processing.create" : "processing.update",
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
2020-10-08 16:53:43 +06:30
|
|
|
),
|
2020-12-01 19:02:21 +06:30
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 12.0, right: 12),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 10,
|
2020-10-12 08:26:27 +06:30
|
|
|
),
|
2020-12-01 19:02:21 +06:30
|
|
|
Row(
|
|
|
|
|
children: [
|
|
|
|
|
Flexible(child: consigneeBox),
|
|
|
|
|
Flexible(child: shipperBox)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
Divider(),
|
|
|
|
|
packageTitleBox,
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: _getPackages(context, packages),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
),
|
2020-12-02 20:55:00 +06:30
|
|
|
createButton,
|
2020-12-01 19:02:21 +06:30
|
|
|
SizedBox(
|
|
|
|
|
height: 10,
|
2020-10-12 08:26:27 +06:30
|
|
|
),
|
|
|
|
|
],
|
2020-10-08 16:53:43 +06:30
|
|
|
),
|
|
|
|
|
),
|
2020-12-01 19:02:21 +06:30
|
|
|
));
|
2020-10-08 16:53:43 +06:30
|
|
|
}
|
|
|
|
|
|
2020-12-01 19:02:21 +06:30
|
|
|
List<Widget> _getPackages(BuildContext context, List<Package> packages) {
|
|
|
|
|
return packages.map((p) {
|
|
|
|
|
return Container(
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
border: Border(
|
|
|
|
|
bottom: BorderSide(color: Colors.grey[300]),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
child: InkWell(
|
2020-12-02 20:55:00 +06:30
|
|
|
onTap: () async {
|
|
|
|
|
Package _package = await Navigator.of(context).push<Package>(
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => PackageEditor(package: p)));
|
|
|
|
|
// setState(() {
|
|
|
|
|
// _savePackage(_package);
|
|
|
|
|
// });
|
|
|
|
|
_savePackage(_package);
|
2020-12-01 19:02:21 +06:30
|
|
|
},
|
|
|
|
|
child: Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Expanded(
|
|
|
|
|
child: new Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 5.0),
|
|
|
|
|
child: new Row(
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
new Padding(
|
|
|
|
|
padding: new EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 30.0 - 15.0 / 2),
|
|
|
|
|
child: Stack(
|
|
|
|
|
alignment: AlignmentDirectional.bottomEnd,
|
|
|
|
|
children: [
|
|
|
|
|
Icon(
|
|
|
|
|
Octicons.package,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
size: 30,
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
new Expanded(
|
|
|
|
|
child: new Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
new Text(
|
|
|
|
|
p.trackingID,
|
|
|
|
|
style: new TextStyle(fontSize: 15.0),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
IconButton(
|
|
|
|
|
icon: Icon(Icons.remove, color: primaryColor),
|
2020-12-02 20:55:00 +06:30
|
|
|
onPressed: () => _removePackage(p),
|
2020-12-01 19:02:21 +06:30
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList();
|
2020-10-08 16:53:43 +06:30
|
|
|
}
|
|
|
|
|
|
2020-12-02 20:55:00 +06:30
|
|
|
_addPackage(Package package) {
|
|
|
|
|
if (package == null) return;
|
|
|
|
|
|
|
|
|
|
this.packages.add(package);
|
|
|
|
|
setState(() {});
|
2020-12-01 19:02:21 +06:30
|
|
|
}
|
|
|
|
|
|
2020-12-02 20:55:00 +06:30
|
|
|
_savePackage(Package package) {
|
|
|
|
|
if (package == null) return;
|
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_removePackage(Package package) {
|
|
|
|
|
if (package == null) return;
|
|
|
|
|
this.packages.removeWhere((p) => p.trackingID == package.trackingID);
|
|
|
|
|
setState(() {});
|
2020-12-01 19:02:21 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_save() async {
|
2020-10-08 16:53:43 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
2020-12-01 19:02:21 +06:30
|
|
|
|
|
|
|
|
ProcessingModel processingModel =
|
|
|
|
|
Provider.of<ProcessingModel>(context, listen: false);
|
2020-10-08 16:53:43 +06:30
|
|
|
try {
|
2020-12-01 19:02:21 +06:30
|
|
|
if (_isNew) {
|
|
|
|
|
await processingModel.createProcessing(processing);
|
|
|
|
|
} else {
|
|
|
|
|
processing.id = widget.processing.id;
|
|
|
|
|
await processingModel.updateProcessing(processing);
|
|
|
|
|
}
|
2020-10-08 16:53:43 +06:30
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|