270 lines
9.1 KiB
Dart
270 lines
9.1 KiB
Dart
import 'package:fcs/domain/constants.dart';
|
|
import 'package:fcs/domain/entities/box.dart';
|
|
import 'package:fcs/domain/entities/cargo.dart';
|
|
import 'package:fcs/domain/entities/pickup.dart';
|
|
import 'package:fcs/domain/vo/delivery_address.dart';
|
|
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:fcs/pages/box/model/box_model.dart';
|
|
import 'package:fcs/pages/delivery_address/model/delivery_address_model.dart';
|
|
import 'package:fcs/pages/main/model/main_model.dart';
|
|
import 'package:fcs/pages/shipment/model/shipment_model.dart';
|
|
import 'package:fcs/pages/widgets/bottom_up_page_route.dart';
|
|
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
|
import 'package:fcs/pages/widgets/delivery_address_selection.dart';
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
|
import 'package:fcs/pages/widgets/input_date.dart';
|
|
import 'package:fcs/pages/widgets/input_time.dart';
|
|
import 'package:fcs/pages/widgets/local_button.dart';
|
|
import 'package:fcs/pages/widgets/local_dropdown.dart';
|
|
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:fcs/pages/widgets/local_title.dart';
|
|
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
import 'package:fcs/pages/widgets/title_with_add_button.dart';
|
|
import 'package:flutter/material.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 'box_row.dart';
|
|
import 'shipment_box_editor.dart';
|
|
|
|
enum SingingCharacter { lafayette, jefferson }
|
|
|
|
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');
|
|
final numberFormatter = new NumberFormat("#,###");
|
|
MultiImgController multiImgController = MultiImgController();
|
|
|
|
TextEditingController _addressEditingController = new TextEditingController();
|
|
TextEditingController _fromTimeEditingController =
|
|
new TextEditingController();
|
|
TextEditingController _toTimeEditingController = new TextEditingController();
|
|
TextEditingController _noOfPackageEditingController =
|
|
new TextEditingController();
|
|
TextEditingController _weightEditingController = new TextEditingController();
|
|
TextEditingController _recipientNameEditingController =
|
|
new TextEditingController();
|
|
TextEditingController _recipientPhoneEditingController =
|
|
new TextEditingController();
|
|
TextEditingController _recipientAddressEditingController =
|
|
new TextEditingController();
|
|
TextEditingController _pickupDate = new TextEditingController();
|
|
TextEditingController _handlingFeeController = new TextEditingController();
|
|
|
|
Shipment _pickUp;
|
|
bool _isLoading = false;
|
|
var now = new DateTime.now();
|
|
bool _isNew;
|
|
DeliveryAddress _pickupAddress = new DeliveryAddress();
|
|
|
|
int _currVal = 1;
|
|
String _selectedPickupType;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_selectedPickupType = shipment_local_pickup;
|
|
|
|
if (widget.shipment != null) {
|
|
_isNew = false;
|
|
_pickUp = widget.shipment;
|
|
_addressEditingController.text = _pickUp.address;
|
|
_fromTimeEditingController.text = _pickUp.fromTime;
|
|
_toTimeEditingController.text = _pickUp.toTime;
|
|
_noOfPackageEditingController.text = _pickUp.numberOfPackage.toString();
|
|
_weightEditingController.text = _pickUp.weight.toString();
|
|
_pickupDate.text = dateFormatter.format(now);
|
|
_handlingFeeController.text = numberFormatter.format(_pickUp.handlingFee);
|
|
_currVal = _pickUp.radioIndex;
|
|
} else {
|
|
_isNew = true;
|
|
_pickupDate.text = dateFormatter.format(now);
|
|
_fromTimeEditingController.text = "${(now.hour)}:${(now.minute)}";
|
|
_toTimeEditingController.text = "${(now.hour)}:${(now.minute)}";
|
|
List<Cargo> _cargoTypes = [
|
|
Cargo(type: 'General Cargo', weight: 25),
|
|
Cargo(type: 'Medicine', weight: 20),
|
|
Cargo(type: 'Dangerous Cargo', weight: 30)
|
|
];
|
|
_pickUp = Shipment(cargoTypes: _cargoTypes);
|
|
}
|
|
var shipmentModel =
|
|
Provider.of<DeliveryAddressModel>(context, listen: false);
|
|
_pickupAddress = shipmentModel.defalutAddress;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
SingingCharacter _character = SingingCharacter.lafayette;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
MainModel mainModel = Provider.of<MainModel>(context);
|
|
ShipmentModel pickupModel = Provider.of<ShipmentModel>(context);
|
|
|
|
final fromTimeBox = InputTime(
|
|
labelTextKey: 'shipment.from',
|
|
iconData: Icons.timer,
|
|
controller: _fromTimeEditingController);
|
|
|
|
final toTimeBox = Container(
|
|
width: 150,
|
|
child: InputTime(
|
|
iconData: Icons.timer_off,
|
|
labelTextKey: 'shipment.to',
|
|
controller: _toTimeEditingController));
|
|
|
|
final pickupDateBox = InputDate(
|
|
labelTextKey: "shipment.date",
|
|
iconData: Icons.date_range,
|
|
controller: _pickupDate,
|
|
);
|
|
final localDropoffAddress = DisplayText(
|
|
iconData: Icons.location_on,
|
|
labelTextKey: "Local Dropoff Address",
|
|
text: mainModel.setting.usaAddress);
|
|
final curierDropoffAddress = FloatingActionButton.extended(
|
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
|
onPressed: () {},
|
|
icon: Icon(Icons.arrow_right),
|
|
label: Text(
|
|
'Visit courier websie for nearest drop-off',
|
|
style: TextStyle(fontSize: 12),
|
|
),
|
|
backgroundColor: primaryColor,
|
|
);
|
|
final pickupAddressBox = DefaultDeliveryAddress(
|
|
deliveryAddress: _pickupAddress,
|
|
iconData: Icons.location_on,
|
|
labelKey: "shipment.location",
|
|
onTap: () async {
|
|
DeliveryAddress d = await Navigator.push<DeliveryAddress>(
|
|
context,
|
|
BottomUpPageRoute(DeliveryAddressSelection(
|
|
deliveryAddress: _pickupAddress,
|
|
)),
|
|
);
|
|
if (d == null) return;
|
|
setState(() {
|
|
this._pickupAddress = d;
|
|
});
|
|
},
|
|
);
|
|
var boxModel = Provider.of<BoxModel>(context);
|
|
var handlingFeeBox = DisplayText(
|
|
labelTextKey: "shipment.handling.fee",
|
|
text: "10",
|
|
iconData: FontAwesomeIcons.moneyBill);
|
|
var shipmentTypeBox = LocalDropdown<String>(
|
|
callback: (v) {
|
|
setState(() {
|
|
_selectedPickupType = v;
|
|
});
|
|
},
|
|
iconData: SimpleLineIcons.direction,
|
|
selectedValue: _selectedPickupType,
|
|
values: pickupModel.pickupTypes,
|
|
);
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
centerTitle: true,
|
|
leading: new IconButton(
|
|
icon: new Icon(
|
|
Icons.close,
|
|
color: primaryColor,
|
|
),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
),
|
|
shadowColor: Colors.transparent,
|
|
backgroundColor: Colors.white,
|
|
title: LocalText(
|
|
context,
|
|
_isNew ? "shipment.new.title" : "shipment.edit.title",
|
|
fontSize: 20,
|
|
color: primaryColor,
|
|
),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: ListView(
|
|
children: <Widget>[
|
|
LocalTitle(textKey: "shipment.type"),
|
|
LocalRadioButtons(
|
|
values: pickupModel.pickupTypes,
|
|
selectedValue: _selectedPickupType,
|
|
callback: (v) {
|
|
setState(() {
|
|
_selectedPickupType = v;
|
|
});
|
|
}),
|
|
// handlingFeeBox,
|
|
// shipmentTypeBox,
|
|
LocalTitle(textKey: "shipment.location"),
|
|
pickupAddressBox,
|
|
LocalTitle(textKey: "shipment.date.time"),
|
|
pickupDateBox,
|
|
fromTimeBox,
|
|
toTimeBox,
|
|
// localDropoffAddress,
|
|
// curierDropoffAddress,
|
|
LocalTitle(
|
|
textKey: "boxes.name",
|
|
trailing: IconButton(
|
|
icon: Icon(
|
|
Icons.add_circle,
|
|
color: primaryColor,
|
|
),
|
|
onPressed: () {
|
|
Navigator.push(
|
|
context,
|
|
BottomUpPageRoute(ShipmentBoxEditor()),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
|
|
Column(
|
|
children: getBoxList(context, boxModel.boxes),
|
|
),
|
|
LocalButton(
|
|
textKey: "shipment.new",
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Widget> getBoxList(BuildContext context, List<Box> boxes) {
|
|
return boxes.asMap().entries.map((_box) {
|
|
return InkWell(
|
|
onTap: () {
|
|
Navigator.of(context)
|
|
.push(BottomUpPageRoute(ShipmentBoxEditor(box: _box.value)));
|
|
},
|
|
child: BoxRow(box: _box.value),
|
|
);
|
|
}).toList();
|
|
}
|
|
|
|
_addBox() {}
|
|
}
|