2021-09-13 17:36:52 +06:30
|
|
|
import 'package:fcs/domain/entities/market.dart';
|
|
|
|
|
import 'package:fcs/domain/entities/package.dart';
|
2021-10-09 17:08:28 +06:30
|
|
|
import 'package:fcs/domain/entities/pickup.dart';
|
2021-09-13 17:36:52 +06:30
|
|
|
import 'package:fcs/helpers/theme.dart';
|
|
|
|
|
import 'package:fcs/pages/market/market_editor.dart';
|
|
|
|
|
import 'package:fcs/pages/market/model/market_model.dart';
|
|
|
|
|
import 'package:fcs/pages/package/tracking_id_page.dart';
|
|
|
|
|
import 'package:fcs/pages/main/util.dart';
|
2021-10-09 17:08:28 +06:30
|
|
|
import 'package:fcs/pages/pickup/model/pickup_model.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/defalut_delivery_address.dart';
|
2021-09-13 17:36:52 +06:30
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/input_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/multi_img_controller.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/multi_img_file.dart';
|
|
|
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
|
|
class PickupEditor extends StatefulWidget {
|
2021-10-09 17:08:28 +06:30
|
|
|
final Pickup? pickup;
|
|
|
|
|
|
|
|
|
|
const PickupEditor({Key? key, this.pickup}) : super(key: key);
|
2021-09-13 17:36:52 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_PickupEditorState createState() => _PickupEditorState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PickupEditorState extends State<PickupEditor> {
|
2021-10-09 17:08:28 +06:30
|
|
|
var dateFormatter = new DateFormat('dd MMM yyyy');
|
|
|
|
|
var timeFormatter = new DateFormat('h:mm a');
|
|
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
TextEditingController _remarkCtl = new TextEditingController();
|
2021-10-09 17:08:28 +06:30
|
|
|
MultiImgController multiImgController = MultiImgController();
|
2021-09-13 17:36:52 +06:30
|
|
|
|
2021-10-09 17:08:28 +06:30
|
|
|
Pickup? _pickup;
|
2021-09-13 17:36:52 +06:30
|
|
|
bool _isLoading = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2021-10-09 17:08:28 +06:30
|
|
|
_pickup = widget.pickup;
|
|
|
|
|
multiImgController.setImageUrls = _pickup!.photoUrls;
|
2021-09-13 17:36:52 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2021-10-09 17:08:28 +06:30
|
|
|
final pickupNumberBox = DisplayText(
|
|
|
|
|
text: _pickup!.pickupNumber ?? "",
|
|
|
|
|
labelTextKey: "pickup.pickup_number",
|
|
|
|
|
iconData: SimpleLineIcons.direction,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final pickupDateBox = DisplayText(
|
|
|
|
|
text: _pickup!.pickupDate == null
|
|
|
|
|
? ""
|
|
|
|
|
: dateFormatter.format(_pickup!.pickupDate!),
|
|
|
|
|
labelTextKey: "pickup.date",
|
|
|
|
|
iconData: Icons.date_range,
|
|
|
|
|
);
|
|
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
var timeBox = Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Container(
|
|
|
|
|
width: 150,
|
|
|
|
|
child: DisplayText(
|
2021-10-09 17:08:28 +06:30
|
|
|
text: _pickup!.fromTime == null
|
|
|
|
|
? ""
|
|
|
|
|
: timeFormatter.format(_pickup!.fromTime!),
|
2021-09-14 11:03:03 +06:30
|
|
|
labelTextKey: "pickup.from_time",
|
|
|
|
|
iconData: MaterialCommunityIcons.clock_start,
|
2021-09-13 17:36:52 +06:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
width: 150,
|
|
|
|
|
child: DisplayText(
|
2021-10-09 17:08:28 +06:30
|
|
|
text: _pickup!.toTime == null
|
|
|
|
|
? ""
|
|
|
|
|
: timeFormatter.format(_pickup!.toTime!),
|
|
|
|
|
labelTextKey: "pickup.to_time",
|
|
|
|
|
iconData: MaterialCommunityIcons.clock_end,
|
|
|
|
|
),
|
2021-09-13 17:36:52 +06:30
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
2021-10-09 17:08:28 +06:30
|
|
|
final customerBox = DisplayText(
|
|
|
|
|
text: _pickup!.customerName ?? "",
|
|
|
|
|
labelTextKey: "pickup.customer",
|
|
|
|
|
iconData: Icons.perm_identity,
|
2021-09-13 17:36:52 +06:30
|
|
|
);
|
|
|
|
|
|
2021-10-09 17:08:28 +06:30
|
|
|
final staffNameBox = DisplayText(
|
|
|
|
|
text: _pickup!.staffName ?? "",
|
|
|
|
|
labelTextKey: "pickup.staff.name",
|
|
|
|
|
iconData: Icons.perm_identity,
|
2021-09-13 17:36:52 +06:30
|
|
|
);
|
2021-10-09 17:08:28 +06:30
|
|
|
|
|
|
|
|
final deliveryAddressBox = DefaultDeliveryAddress(
|
|
|
|
|
deliveryAddress: _pickup!.pickupAddress,
|
|
|
|
|
labelKey: "pickup.delivery.address",
|
|
|
|
|
onTap: null);
|
|
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
final completeProcessingBtn = fcsButton(
|
|
|
|
|
context,
|
|
|
|
|
getLocalString(context, 'pickup.edit.complete.btn'),
|
2021-09-14 11:03:03 +06:30
|
|
|
callack: _confirmComplete,
|
2021-09-13 17:36:52 +06:30
|
|
|
);
|
2021-09-14 11:03:03 +06:30
|
|
|
|
2021-10-09 17:08:28 +06:30
|
|
|
final completeRemarkBox = InputText(
|
|
|
|
|
labelTextKey: 'pickup.complete.remark',
|
2021-09-13 17:36:52 +06:30
|
|
|
iconData: Entypo.new_message,
|
|
|
|
|
controller: _remarkCtl);
|
|
|
|
|
|
2021-09-14 11:03:03 +06:30
|
|
|
final statusBox = DisplayText(
|
2021-10-09 17:08:28 +06:30
|
|
|
text: _pickup != null ? _pickup!.status : "",
|
2021-09-14 11:03:03 +06:30
|
|
|
labelTextKey: "pickup.status",
|
|
|
|
|
iconData: Icons.av_timer,
|
|
|
|
|
);
|
|
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
final img = MultiImageFile(
|
|
|
|
|
enabled: true,
|
|
|
|
|
controller: multiImgController,
|
|
|
|
|
title: "Receipt File",
|
|
|
|
|
);
|
2021-10-09 17:08:28 +06:30
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
return LocalProgress(
|
|
|
|
|
inAsyncCall: _isLoading,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
leading: new IconButton(
|
|
|
|
|
icon: new Icon(CupertinoIcons.back, color: primaryColor, size: 30),
|
|
|
|
|
onPressed: () {
|
|
|
|
|
if (isDataChanged()) {
|
|
|
|
|
showConfirmDialog(context, "back.button_confirm", () {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
shadowColor: Colors.transparent,
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
title: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"pickup.edit.title",
|
|
|
|
|
fontSize: 20,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
body: Padding(
|
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
|
child: ListView(
|
|
|
|
|
children: [
|
|
|
|
|
pickupNumberBox,
|
|
|
|
|
pickupDateBox,
|
|
|
|
|
timeBox,
|
2021-10-09 17:08:28 +06:30
|
|
|
customerBox,
|
2021-09-14 11:03:03 +06:30
|
|
|
staffNameBox,
|
|
|
|
|
statusBox,
|
2021-10-09 17:08:28 +06:30
|
|
|
deliveryAddressBox,
|
|
|
|
|
completeRemarkBox,
|
2021-09-13 17:36:52 +06:30
|
|
|
img,
|
2021-10-09 17:08:28 +06:30
|
|
|
_pickup!.status == "confirmed" || _pickup!.status == "rescheduled"
|
2021-09-13 17:36:52 +06:30
|
|
|
? completeProcessingBtn
|
|
|
|
|
: Container(),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String? selectedMarket;
|
|
|
|
|
Widget marketDropdown() {
|
|
|
|
|
List<Market> _markets = Provider.of<MarketModel>(context).markets;
|
|
|
|
|
List<String?> markets = _markets.map((e) => e.name).toList();
|
|
|
|
|
markets.insert(0, MANAGE_MARKET);
|
|
|
|
|
if (!markets.contains(selectedMarket)) {
|
|
|
|
|
markets.insert(0, selectedMarket!);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 5.0, right: 0),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(left: 0, right: 10),
|
|
|
|
|
child: Icon(Icons.store, color: primaryColor),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.only(right: 18.0),
|
|
|
|
|
child: LocalText(
|
|
|
|
|
context,
|
|
|
|
|
"processing.market",
|
|
|
|
|
color: Colors.black54,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
DropdownButton<String>(
|
|
|
|
|
isDense: true,
|
|
|
|
|
value: selectedMarket,
|
|
|
|
|
style: TextStyle(color: Colors.black, fontSize: 14),
|
|
|
|
|
underline: Container(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: Colors.grey,
|
|
|
|
|
),
|
|
|
|
|
onChanged: (String? newValue) {
|
|
|
|
|
setState(() {
|
|
|
|
|
if (newValue == MANAGE_MARKET) {
|
|
|
|
|
selectedMarket = null;
|
|
|
|
|
_manageMarket();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
selectedMarket = newValue;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
isExpanded: true,
|
|
|
|
|
items: markets.map<DropdownMenuItem<String>>((String? value) {
|
|
|
|
|
return DropdownMenuItem<String>(
|
|
|
|
|
value: value,
|
|
|
|
|
child: Text(value ?? "",
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: value == MANAGE_MARKET
|
|
|
|
|
? secondaryColor
|
|
|
|
|
: primaryColor)),
|
|
|
|
|
);
|
|
|
|
|
}).toList(),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_manageMarket() {
|
|
|
|
|
Navigator.push<Package>(
|
|
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(builder: (context) => MarketEditor()),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-14 11:03:03 +06:30
|
|
|
_completePickup() async {
|
2021-09-13 17:36:52 +06:30
|
|
|
setState(() {
|
|
|
|
|
_isLoading = true;
|
|
|
|
|
});
|
2021-10-09 17:08:28 +06:30
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
try {
|
2021-10-09 17:08:28 +06:30
|
|
|
_pickup?.completeRemark = _remarkCtl.text;
|
|
|
|
|
await context.read<PickupModel>().complete(_pickup!,
|
|
|
|
|
multiImgController.getAddedFile, multiImgController.getDeletedUrl);
|
|
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-14 11:03:03 +06:30
|
|
|
_confirmComplete() {
|
|
|
|
|
showConfirmDialog(context, "pickup.confirm.complete", () {
|
|
|
|
|
_completePickup();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 17:36:52 +06:30
|
|
|
isDataChanged() {
|
2021-10-09 17:08:28 +06:30
|
|
|
var _pickup = Pickup(
|
|
|
|
|
completeRemark: _remarkCtl.text, photoUrls: widget.pickup!.photoUrls);
|
|
|
|
|
return widget.pickup!.isChangedForEdit(_pickup) ||
|
|
|
|
|
multiImgController.getAddedFile.isNotEmpty ||
|
|
|
|
|
multiImgController.getDeletedUrl.isNotEmpty;
|
2021-09-13 17:36:52 +06:30
|
|
|
}
|
|
|
|
|
}
|