insert shipment form
This commit is contained in:
371
lib/pages/shipment_editor.dart
Normal file
371
lib/pages/shipment_editor.dart
Normal file
@@ -0,0 +1,371 @@
|
||||
import 'package:fcs/model/main_model.dart';
|
||||
import 'package:fcs/model/shipment_model.dart';
|
||||
import 'package:fcs/pages/util.dart';
|
||||
import 'package:fcs/vo/shipment.dart';
|
||||
import 'package:fcs/vo/user.dart';
|
||||
import 'package:fcs/widget/label_widgets.dart';
|
||||
import 'package:flutter_icons/flutter_icons.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:fcs/widget/localization/app_translations.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fcs/widget/progress.dart';
|
||||
|
||||
import '../theme/theme.dart';
|
||||
|
||||
class ShipmentEditor extends StatefulWidget {
|
||||
final Shipment shipment;
|
||||
ShipmentEditor({this.shipment});
|
||||
|
||||
@override
|
||||
_ShipmentEditorState createState() => _ShipmentEditorState();
|
||||
}
|
||||
|
||||
class _ShipmentEditorState extends State<ShipmentEditor> {
|
||||
var dateFormatter = new DateFormat('dd MMM yyyy');
|
||||
TextEditingController _shipmentNumberController = new TextEditingController();
|
||||
TextEditingController _cutoffDateController = new TextEditingController();
|
||||
TextEditingController _arrivalDateController = new TextEditingController();
|
||||
TextEditingController _departureDateControler = new TextEditingController();
|
||||
TextEditingController _consigneeController = new TextEditingController();
|
||||
TextEditingController _portController = new TextEditingController();
|
||||
TextEditingController _destinationController = new TextEditingController();
|
||||
TextEditingController _statusController = new TextEditingController();
|
||||
TextEditingController _remarkController = new TextEditingController();
|
||||
|
||||
Shipment _shipment = new Shipment();
|
||||
bool _isLoading = false;
|
||||
String _currentShipment;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (widget.shipment != null) {
|
||||
_shipment = widget.shipment;
|
||||
_shipmentNumberController.text = _shipment.shipmentNumber;
|
||||
_arrivalDateController.text = dateFormatter.format(_shipment.arrivalDate);
|
||||
_departureDateControler.text =
|
||||
dateFormatter.format(_shipment.departureDate);
|
||||
_statusController.text = _shipment.status;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _showCustomerData(User customer) {
|
||||
return Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 8),
|
||||
child: Text(
|
||||
customer.name,
|
||||
style: TextStyle(
|
||||
color: Colors.black87,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 8),
|
||||
child: Text(
|
||||
customer.phoneNumber,
|
||||
style: TextStyle(
|
||||
color: Colors.black87,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
widget.shipment == null
|
||||
? Container()
|
||||
: Padding(
|
||||
padding: const EdgeInsets.only(left: 10.0, top: 8),
|
||||
child: Text(
|
||||
_shipmentNumberController.text,
|
||||
style: TextStyle(
|
||||
color: Colors.black87,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget showShipmentNumber(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(Icons.text_rotation_none),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: labeledText(
|
||||
context, _shipmentNumberController.text, "shipment.number"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget showShipmentTypes(BuildContext context, ShipmentModel shipmentModel) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
Icon(MaterialCommunityIcons.box_shadow),
|
||||
SizedBox(
|
||||
width: 10,
|
||||
),
|
||||
new Flexible(
|
||||
child: Container(
|
||||
width: 200.0,
|
||||
child: DropdownButton<String>(
|
||||
value: _currentShipment,
|
||||
isExpanded: true,
|
||||
hint: Text(
|
||||
'Select shipment type',
|
||||
),
|
||||
onChanged: changedDropDown,
|
||||
items: shipmentModel.shipmentType
|
||||
.map<DropdownMenuItem<String>>((String shipment) {
|
||||
return new DropdownMenuItem<String>(
|
||||
value: shipment,
|
||||
child: new Text(shipment,
|
||||
style:
|
||||
new TextStyle(color: Colors.black87, fontSize: 17)),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
void changedDropDown(selected) {
|
||||
setState(() {
|
||||
_currentShipment = selected;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var shipmentModel = Provider.of<ShipmentModel>(context);
|
||||
|
||||
final statusBox = Container(
|
||||
padding: EdgeInsets.only(top: 10),
|
||||
child: TextFormField(
|
||||
maxLines: null,
|
||||
controller: _statusController,
|
||||
cursorColor: primaryColor,
|
||||
style: textStyle,
|
||||
decoration: new InputDecoration(
|
||||
labelText: 'Status',
|
||||
labelStyle: TextStyle(fontSize: 14, color: Colors.grey),
|
||||
enabledBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
focusedBorder: UnderlineInputBorder(
|
||||
borderSide: BorderSide(color: primaryColor, width: 1.0)),
|
||||
),
|
||||
));
|
||||
|
||||
MainModel mainModel = Provider.of<MainModel>(context);
|
||||
|
||||
final commercialBtn = Container(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
child: FlatButton(
|
||||
child: Text('Download commercial invoice'),
|
||||
color: primaryColor,
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
))),
|
||||
);
|
||||
|
||||
final packingBtn = Container(
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
child: FlatButton(
|
||||
child: Text('Download packing list'),
|
||||
color: primaryColor,
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
))),
|
||||
);
|
||||
|
||||
final dmsBtn = Container(
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
child: FlatButton(
|
||||
child: Text('Download DMS'),
|
||||
color: primaryColor,
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
))),
|
||||
);
|
||||
|
||||
final createBtn = Container(
|
||||
padding: EdgeInsets.only(top: 20),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
child: FlatButton(
|
||||
child: Text('Create'),
|
||||
color: primaryColor,
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
))),
|
||||
);
|
||||
final updateBtn = Container(
|
||||
padding: EdgeInsets.only(top: 5),
|
||||
child: Align(
|
||||
alignment: Alignment.bottomCenter,
|
||||
child: Center(
|
||||
child: Container(
|
||||
width: 250,
|
||||
child: FlatButton(
|
||||
child: Text('Update'),
|
||||
color: primaryColor,
|
||||
textColor: Colors.white,
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
))),
|
||||
);
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
leading: new IconButton(
|
||||
icon: new Icon(Icons.close),
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
),
|
||||
backgroundColor: primaryColor,
|
||||
title: Text(AppTranslations.of(context).text("shipment.form.title")),
|
||||
),
|
||||
body: Card(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: ListView(children: <Widget>[
|
||||
_showCustomerData(mainModel.customer),
|
||||
widget.shipment == null
|
||||
? fcsInput('Shipment number', Icons.text_rotation_none,
|
||||
controller: _shipmentNumberController)
|
||||
: Container(),
|
||||
widget.shipment == null
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: fcsInput('Cutoff date', Icons.date_range,
|
||||
controller: _cutoffDateController),
|
||||
)
|
||||
: Container(),
|
||||
widget.shipment == null
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: showShipmentTypes(context, shipmentModel))
|
||||
: Container(),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: fcsInput('Arrival date', Icons.date_range,
|
||||
controller: _arrivalDateController),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: fcsInput('Departure date', Icons.date_range,
|
||||
controller: _departureDateControler),
|
||||
),
|
||||
widget.shipment == null
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: fcsInput('Consignee', Icons.work,
|
||||
controller: _consigneeController),
|
||||
)
|
||||
: Container(),
|
||||
widget.shipment == null
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: fcsInput(
|
||||
'Port of loading', FontAwesomeIcons.ship,
|
||||
controller: _portController),
|
||||
)
|
||||
: Container(),
|
||||
widget.shipment == null
|
||||
? Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: fcsInput('Final destination',
|
||||
MaterialCommunityIcons.location_enter,
|
||||
controller: _destinationController),
|
||||
)
|
||||
: Container(),
|
||||
widget.shipment == null
|
||||
? Container()
|
||||
: Row(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(top: 15, right: 8.0),
|
||||
child: Image.asset(
|
||||
'assets/status.png',
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
),
|
||||
Expanded(child: statusBox)
|
||||
],
|
||||
),
|
||||
widget.shipment == null
|
||||
? Container()
|
||||
: Container(
|
||||
padding: EdgeInsets.only(top: 15),
|
||||
child: fcsInput('Remark', MaterialCommunityIcons.note,
|
||||
controller: _remarkController),
|
||||
),
|
||||
widget.shipment == null ? Container() : commercialBtn,
|
||||
widget.shipment == null ? Container() : packingBtn,
|
||||
widget.shipment == null ? Container() : dmsBtn,
|
||||
widget.shipment == null ? createBtn : updateBtn,
|
||||
SizedBox(height: 15)
|
||||
]),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user