482 lines
19 KiB
Dart
482 lines
19 KiB
Dart
import 'package:fcs/model/main_model.dart';
|
|
import 'package:fcs/model/pickup_model.dart';
|
|
import 'package:fcs/pages/util.dart';
|
|
import 'package:fcs/vo/cargo.dart';
|
|
import 'package:fcs/vo/pickup.dart';
|
|
import 'package:fcs/widget/fcs_text_field.dart';
|
|
import 'package:fcs/widget/fcs_text_field_readonly.dart';
|
|
import 'package:flutter_datetime_picker/flutter_datetime_picker.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 PickUpEditor extends StatefulWidget {
|
|
final PickUp pickUp;
|
|
PickUpEditor({this.pickUp});
|
|
|
|
@override
|
|
_PickUpEditorState createState() => _PickUpEditorState();
|
|
}
|
|
|
|
class _PickUpEditorState extends State<PickUpEditor> {
|
|
var dateFormatter = new DateFormat('dd MMM yyyy');
|
|
final numberFormatter = new NumberFormat("#,###");
|
|
|
|
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();
|
|
|
|
PickUp _pickUp;
|
|
bool _isLoading = false;
|
|
var now = new DateTime.now();
|
|
bool isNew;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
if (widget.pickUp != null) {
|
|
isNew = false;
|
|
_pickUp = widget.pickUp;
|
|
_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);
|
|
|
|
var mainModel = Provider.of<MainModel>(context, listen: false);
|
|
_recipientNameEditingController.text = mainModel.recipient.name;
|
|
_recipientPhoneEditingController.text = mainModel.recipient.phoneNumber;
|
|
_recipientAddressEditingController.text =
|
|
mainModel.recipient.shippingAddress;
|
|
} else {
|
|
isNew = true;
|
|
List<Cargo> _cargoTypes = [
|
|
Cargo(type: 'General Cargo', weight: 25),
|
|
Cargo(type: 'Medicine', weight: 20),
|
|
Cargo(type: 'Dangerous Cargo', weight: 30)
|
|
];
|
|
_pickUp = PickUp(cargoTypes: _cargoTypes);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
var pickupModel = Provider.of<PickUpModel>(context);
|
|
|
|
final pickUpAddress = fcsInput('Pickup Address', Icons.location_on,
|
|
controller: _addressEditingController);
|
|
|
|
final pickUpAddressReadOnly = fcsInputReadOnly(
|
|
'Pickup Address', Icons.location_on,
|
|
controller: _addressEditingController);
|
|
|
|
final fromTimeBox = fcsInput(
|
|
'From',
|
|
Icons.timer,
|
|
controller: _fromTimeEditingController,
|
|
);
|
|
|
|
final toTimeBox = fcsInput(
|
|
'To',
|
|
null,
|
|
controller: _toTimeEditingController,
|
|
);
|
|
|
|
final fromTimeBoxReadOnly = fcsInputReadOnly(
|
|
'From',
|
|
Icons.timer,
|
|
controller: _fromTimeEditingController,
|
|
);
|
|
|
|
final toTimeBoxReadOnly = fcsInputReadOnly(
|
|
'To',
|
|
null,
|
|
controller: _toTimeEditingController,
|
|
);
|
|
|
|
final pickupTime = Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: Row(
|
|
children: <Widget>[
|
|
Container(
|
|
child: fromTimeBox,
|
|
width: 120,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
child: Text('-'),
|
|
),
|
|
Container(
|
|
child: toTimeBox,
|
|
width: 120,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
final pickupTimeReadOnly = Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: Row(
|
|
children: <Widget>[
|
|
SizedBox(height: 5),
|
|
Container(
|
|
child: fromTimeBoxReadOnly,
|
|
width: 120,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 8.0),
|
|
child: Text('-'),
|
|
),
|
|
Container(
|
|
child: toTimeBoxReadOnly,
|
|
width: 120,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
|
|
final noOfPackageBox = fcsInput(
|
|
'Number of Packages',
|
|
Octicons.package,
|
|
controller: _noOfPackageEditingController,
|
|
);
|
|
|
|
final noOfPackageBoxReadonly = fcsInputReadOnly(
|
|
'Number of Packages',
|
|
Octicons.package,
|
|
controller: _noOfPackageEditingController,
|
|
);
|
|
|
|
final requestDateBox = Container(
|
|
child: InkWell(
|
|
onTap: () {
|
|
DatePicker.showDatePicker(
|
|
context,
|
|
showTitleActions: true,
|
|
currentTime: _pickupDate.text == ""
|
|
? null
|
|
: dateFormatter.parse(_pickupDate.text),
|
|
minTime: DateTime.now(),
|
|
maxTime: DateTime(2030, 12, 31),
|
|
onConfirm: (date) {},
|
|
locale: LocaleType.en,
|
|
);
|
|
},
|
|
child: TextFormField(
|
|
controller: _pickupDate,
|
|
autofocus: false,
|
|
cursorColor: primaryColor,
|
|
style: textStyle,
|
|
enabled: false,
|
|
keyboardType: TextInputType.datetime,
|
|
decoration: new InputDecoration(
|
|
border: InputBorder.none,
|
|
focusedBorder: InputBorder.none,
|
|
labelText: AppTranslations.of(context).text("pickup.date"),
|
|
// labelStyle: languageModel.isEng ? labelStyle : labelStyleMM,
|
|
contentPadding:
|
|
EdgeInsets.symmetric(vertical: 10.0, horizontal: 0.0),
|
|
icon: Icon(
|
|
Icons.date_range,
|
|
color: primaryColor,
|
|
)),
|
|
validator: (value) {
|
|
if (value.isEmpty) {
|
|
return AppTranslations.of(context).text("do.form.date");
|
|
}
|
|
return null;
|
|
},
|
|
),
|
|
));
|
|
|
|
MainModel mainModel = Provider.of<MainModel>(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("pickup.edit.title")),
|
|
),
|
|
body: Card(
|
|
child: Column(
|
|
children: <Widget>[
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: ListView(children: <Widget>[
|
|
Center(child: nameWidget(mainModel.customer.name)),
|
|
Center(child: nameWidget(mainModel.customer.phoneNumber)),
|
|
isNew
|
|
? Container()
|
|
: Center(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 10.0, top: 8),
|
|
child: Text(
|
|
'#P200304',
|
|
style: TextStyle(
|
|
color: Colors.black87,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.bold),
|
|
),
|
|
),
|
|
),
|
|
ExpansionTile(
|
|
title: Text('Pickup Location / Time'),
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: widget.pickUp == null
|
|
? pickUpAddress
|
|
: widget.pickUp.status == 'Pending'
|
|
? pickUpAddress
|
|
: pickUpAddressReadOnly,
|
|
),
|
|
widget.pickUp == null
|
|
? pickupTime
|
|
: widget.pickUp.status == 'Pending'
|
|
? pickupTime
|
|
: pickupTimeReadOnly,
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: Column(
|
|
children: <Widget>[
|
|
SizedBox(height: 5),
|
|
Container(height: 50.0, child: requestDateBox)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
ExpansionTile(
|
|
title: Text('Package Information'),
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: widget.pickUp == null
|
|
? noOfPackageBox
|
|
: widget.pickUp.status == 'Pending'
|
|
? noOfPackageBox
|
|
: noOfPackageBoxReadonly,
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: widget.pickUp == null
|
|
? fcsInput("Total Weight (lb)",
|
|
FontAwesomeIcons.weightHanging,
|
|
controller: _weightEditingController)
|
|
: widget.pickUp.status == 'Pending'
|
|
? fcsInput("Total Weight (lb)",
|
|
FontAwesomeIcons.weightHanging,
|
|
controller: _weightEditingController)
|
|
: fcsInputReadOnly("Total Weight (lb)",
|
|
FontAwesomeIcons.weightHanging,
|
|
controller: _weightEditingController),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: widget.pickUp == null
|
|
? fcsInput(
|
|
"Handling Fee", FontAwesomeIcons.moneyBill,
|
|
controller: _handlingFeeController)
|
|
: widget.pickUp.status == 'Pending'
|
|
? fcsInput(
|
|
"Handling Fee", FontAwesomeIcons.moneyBill,
|
|
controller: _handlingFeeController)
|
|
: fcsInputReadOnly(
|
|
"Handling Fee", FontAwesomeIcons.moneyBill,
|
|
controller: _handlingFeeController),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: fcsInput("Remark", MaterialCommunityIcons.note),
|
|
),
|
|
SizedBox(height: 10.0),
|
|
],
|
|
),
|
|
// ExpansionTile(
|
|
// title: Text('Box Information'),
|
|
// children: <Widget>[
|
|
// SizedBox(height: 10.0),
|
|
// ],
|
|
// ),
|
|
ExpansionTile(
|
|
title: Text('Shipping Address'),
|
|
children: <Widget>[
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: widget.pickUp == null
|
|
? fcsInput("Name", FontAwesomeIcons.user,
|
|
controller: _recipientNameEditingController)
|
|
: widget.pickUp.status == 'Pending'
|
|
? fcsInput("Name", FontAwesomeIcons.user,
|
|
controller:
|
|
_recipientNameEditingController)
|
|
: fcsInputReadOnly(
|
|
"Name", FontAwesomeIcons.user,
|
|
controller:
|
|
_recipientNameEditingController)),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: widget.pickUp == null
|
|
? fcsInput("Phone Number", Icons.phone,
|
|
controller: _recipientPhoneEditingController)
|
|
: widget.pickUp.status == 'Pending'
|
|
? fcsInput("Phone Number", Icons.phone,
|
|
controller:
|
|
_recipientPhoneEditingController)
|
|
: fcsInputReadOnly(
|
|
"Phone Number", Icons.phone,
|
|
controller:
|
|
_recipientPhoneEditingController)),
|
|
Padding(
|
|
padding: const EdgeInsets.only(left: 20.0),
|
|
child: widget.pickUp == null
|
|
? fcsInput("Address", Icons.location_on,
|
|
controller:
|
|
_recipientAddressEditingController)
|
|
: widget.pickUp.status == 'Pending'
|
|
? fcsInput("Address", Icons.location_on,
|
|
controller:
|
|
_recipientAddressEditingController)
|
|
: fcsInputReadOnly(
|
|
"Address", Icons.location_on,
|
|
controller:
|
|
_recipientAddressEditingController)),
|
|
],
|
|
),
|
|
mainModel.isCustomer()
|
|
? Container()
|
|
: ExpansionTile(
|
|
title: Text('For FCS'),
|
|
children: <Widget>[
|
|
widget.pickUp != null
|
|
? widget.pickUp.status == 'Pending'
|
|
? Padding(
|
|
padding:
|
|
const EdgeInsets.only(left: 20.0),
|
|
child: fcsDropDown("Assigned",
|
|
MaterialCommunityIcons.worker),
|
|
)
|
|
: Container()
|
|
: Container(),
|
|
],
|
|
),
|
|
]),
|
|
)),
|
|
widget.pickUp == null
|
|
? Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Center(
|
|
child: Container(
|
|
width: 250,
|
|
child: FlatButton(
|
|
child: Text('Request for pickup'),
|
|
color: primaryColor,
|
|
textColor: Colors.white,
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
)))
|
|
: Container(
|
|
child: Column(
|
|
children: <Widget>[
|
|
widget.pickUp.status == 'Assigned'
|
|
? Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Center(
|
|
child: Container(
|
|
width: 250,
|
|
child: FlatButton(
|
|
child: Text('Complete'),
|
|
color: primaryColor,
|
|
textColor: Colors.white,
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
)))
|
|
: Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Center(
|
|
child: Container(
|
|
width: 250,
|
|
child: FlatButton(
|
|
child: Text('Assign'),
|
|
color: primaryColor,
|
|
textColor: Colors.white,
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
))),
|
|
Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Center(
|
|
child: Container(
|
|
width: 250,
|
|
child: FlatButton(
|
|
child: Text('Complete Pickup '),
|
|
color: primaryColor,
|
|
textColor: Colors.white,
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
))),
|
|
Align(
|
|
alignment: Alignment.bottomCenter,
|
|
child: Center(
|
|
child: Container(
|
|
width: 250,
|
|
child: FlatButton(
|
|
child: Text('Cancel Pickup'),
|
|
color: Colors.grey[600],
|
|
textColor: Colors.white,
|
|
onPressed: () {
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
)))
|
|
],
|
|
))
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|