2025-03-06 17:59:15 +06:30
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
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';
|
2021-01-05 18:03:51 +06:30
|
|
|
import 'package:fcs/pages/package/package_info.dart';
|
2024-02-07 17:26:29 +06:30
|
|
|
import 'package:fcs/pages/user_search/user_search.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
import 'package:fcs/pages/widgets/display_text.dart';
|
2024-01-25 17:40:35 +06:30
|
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
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';
|
2021-09-10 12:00:08 +06:30
|
|
|
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
|
2020-10-08 16:53:43 +06:30
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
2025-03-06 17:59:15 +06:30
|
|
|
import '../../domain/entities/fcs_shipment.dart';
|
|
|
|
|
import '../fcs_shipment/model/fcs_shipment_model.dart';
|
|
|
|
|
import '../widgets/local_dropdown.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 {
|
2025-03-06 17:59:15 +06:30
|
|
|
const ProcesingEditor({super.key});
|
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;
|
2025-03-06 17:59:15 +06:30
|
|
|
User? _consignee;
|
|
|
|
|
User? _sender;
|
2020-12-01 19:02:21 +06:30
|
|
|
List<Package> packages = [];
|
2025-03-06 17:59:15 +06:30
|
|
|
List<FcsShipment> _shipments = [];
|
|
|
|
|
FcsShipment? _shipment;
|
2020-10-08 16:53:43 +06:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
2025-03-06 17:59:15 +06:30
|
|
|
_loadShipment();
|
2020-10-08 16:53:43 +06:30
|
|
|
super.initState();
|
2025-03-06 17:59:15 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_loadShipment() async {
|
|
|
|
|
var fcsShipments =
|
|
|
|
|
await context.read<FcsShipmentModel>().getActiveFcsShipments();
|
|
|
|
|
_shipments = fcsShipments;
|
|
|
|
|
|
|
|
|
|
if (mounted) {
|
|
|
|
|
setState(() {});
|
2020-12-01 19:02:21 +06:30
|
|
|
}
|
2020-10-08 16:53:43 +06:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2025-03-06 17:59:15 +06:30
|
|
|
final consigneeBox = userSearchBox(context,
|
|
|
|
|
lableKey: 'box.consignee.title',
|
|
|
|
|
icon: MaterialCommunityIcons.account_arrow_left,
|
|
|
|
|
user: _consignee,
|
|
|
|
|
onSearch: () => searchUser(context, onUserSelect: (u) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_consignee = u;
|
|
|
|
|
});
|
|
|
|
|
}, popPage: true));
|
|
|
|
|
|
|
|
|
|
final senderBox = userSearchBox(context,
|
|
|
|
|
lableKey: 'box.sender.title',
|
|
|
|
|
icon: MaterialCommunityIcons.account_arrow_right,
|
|
|
|
|
user: _sender,
|
|
|
|
|
onSearch: () => searchUser(context, onUserSelect: (u) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_sender = u;
|
|
|
|
|
});
|
|
|
|
|
}, popPage: true));
|
|
|
|
|
|
|
|
|
|
final fcsShipmentsBox = Container(
|
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 15),
|
|
|
|
|
child: LocalDropdown<FcsShipment>(
|
|
|
|
|
callback: (v) {
|
|
|
|
|
setState(() {
|
|
|
|
|
_shipment = v;
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
labelKey: "box.shipment",
|
|
|
|
|
iconData: Ionicons.ios_airplane,
|
|
|
|
|
display: (u) => u.shipmentNumber,
|
|
|
|
|
selectedValue: _shipment,
|
|
|
|
|
values: _shipments,
|
|
|
|
|
));
|
2020-12-01 19:02:21 +06:30
|
|
|
|
2025-03-06 17:59:15 +06:30
|
|
|
final packageTitleBox = Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
|
children: [
|
|
|
|
|
Text("Packages (${packages.length})"),
|
2020-12-01 19:02:21 +06:30
|
|
|
IconButton(
|
2025-03-06 17:59:15 +06:30
|
|
|
icon: Icon(
|
|
|
|
|
Icons.add_circle,
|
|
|
|
|
color: primaryColor,
|
|
|
|
|
),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
if (_consignee == null) {
|
|
|
|
|
showMsgDialog(context, "Error", "Please select consignee");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_sender == null) {
|
|
|
|
|
showMsgDialog(context, "Error", "Please select sender");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_shipment == null) {
|
|
|
|
|
showMsgDialog(context, "Error", "Please select shipment");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Package? package = await Navigator.push<Package>(
|
|
|
|
|
context,
|
|
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => PackageEditor(
|
|
|
|
|
sender: _sender!,
|
|
|
|
|
consignee: _consignee!,
|
|
|
|
|
shipment: _shipment!)),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
_addPackage(package);
|
|
|
|
|
// _savePackage(_package);
|
|
|
|
|
}),
|
2020-12-01 19:02:21 +06:30
|
|
|
],
|
2020-10-08 16:53:43 +06:30
|
|
|
);
|
|
|
|
|
|
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(
|
2024-01-25 17:40:35 +06:30
|
|
|
appBar: LocalAppBar(
|
2025-03-06 17:59:15 +06:30
|
|
|
labelKey: "processing.create",
|
2020-12-01 19:02:21 +06:30
|
|
|
backgroundColor: Colors.white,
|
2024-01-25 17:40:35 +06:30
|
|
|
labelColor: primaryColor,
|
|
|
|
|
arrowColor: 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),
|
2025-03-06 17:59:15 +06:30
|
|
|
Flexible(child: senderBox)
|
2020-12-01 19:02:21 +06:30
|
|
|
],
|
|
|
|
|
),
|
2025-03-06 17:59:15 +06:30
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
fcsShipmentsBox,
|
2020-12-01 19:02:21 +06:30
|
|
|
packageTitleBox,
|
|
|
|
|
Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: _getPackages(context, packages),
|
|
|
|
|
),
|
|
|
|
|
SizedBox(
|
|
|
|
|
height: 20,
|
|
|
|
|
),
|
2020-12-02 20:55:00 +06:30
|
|
|
createButton,
|
2025-03-06 17:59:15 +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) {
|
2021-01-05 18:03:51 +06:30
|
|
|
return InkWell(
|
|
|
|
|
onTap: () async {
|
2021-09-10 12:00:08 +06:30
|
|
|
Package? _package = await Navigator.of(context).push<Package>(
|
2021-01-05 18:03:51 +06:30
|
|
|
CupertinoPageRoute(
|
|
|
|
|
builder: (context) => PackageInfo(package: p)));
|
2021-09-10 12:00:08 +06:30
|
|
|
_savePackage(_package!);
|
2021-01-05 18:03:51 +06:30
|
|
|
},
|
|
|
|
|
child: DisplayText(
|
|
|
|
|
labelTextKey: "processing.tracking.id",
|
|
|
|
|
iconData: MaterialCommunityIcons.barcode_scan,
|
|
|
|
|
text: p.trackingID,
|
2020-12-01 19:02:21 +06:30
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}).toList();
|
2020-10-08 16:53:43 +06:30
|
|
|
}
|
|
|
|
|
|
2021-10-11 17:09:47 +06:30
|
|
|
_addPackage(Package? package) {
|
2020-12-02 20:55:00 +06:30
|
|
|
if (package == null) return;
|
|
|
|
|
|
2025-03-06 17:59:15 +06:30
|
|
|
packages.add(package);
|
2020-12-02 20:55:00 +06:30
|
|
|
setState(() {});
|
2020-12-01 19:02:21 +06:30
|
|
|
}
|
|
|
|
|
|
2021-10-11 17:09:47 +06:30
|
|
|
_savePackage(Package? package) {
|
2020-12-02 20:55:00 +06:30
|
|
|
if (package == null) return;
|
|
|
|
|
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 {
|
2025-03-06 17:59:15 +06:30
|
|
|
await processingModel.createProcessing(processing);
|
2020-10-08 16:53:43 +06:30
|
|
|
Navigator.pop(context);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
showMsgDialog(context, "Error", e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
setState(() {
|
|
|
|
|
_isLoading = false;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|