Files
fcs/lib/pages/carton/carton_editor.dart

380 lines
12 KiB
Dart
Raw Normal View History

2020-10-14 16:53:16 +06:30
import 'package:fcs/domain/constants.dart';
2020-10-18 02:38:46 +06:30
import 'package:fcs/domain/entities/carton.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/domain/entities/user.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/helpers/theme.dart';
2020-10-09 17:28:42 +06:30
import 'package:fcs/pages/user_search/user_serach.dart';
import 'package:fcs/pages/widgets/display_text.dart';
import 'package:fcs/pages/widgets/fcs_id_icon.dart';
2024-01-25 17:40:35 +06:30
import 'package:fcs/pages/widgets/local_app_bar.dart';
2024-02-02 18:00:51 +06:30
import 'package:fcs/pages/widgets/local_radio.dart';
2020-10-14 13:17:12 +06:30
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/local_text.dart';
2020-10-14 13:17:12 +06:30
import 'package:fcs/pages/widgets/local_title.dart';
2020-10-07 02:33:06 +06:30
import 'package:fcs/pages/widgets/progress.dart';
2020-10-14 16:53:16 +06:30
import 'package:flutter/cupertino.dart';
2020-06-04 01:36:49 +06:30
import 'package:flutter/material.dart';
2021-09-10 12:00:08 +06:30
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2024-02-05 11:13:12 +06:30
import '../main/util.dart';
import 'carton_editor_for_package.dart';
import 'mix_carton/mix_carton_editor.dart';
2020-12-10 20:06:15 +06:30
import 'carton_row.dart';
2020-10-09 17:28:42 +06:30
2020-10-19 05:13:49 +06:30
class CartonEditor extends StatefulWidget {
2021-09-13 09:51:55 +06:30
final Carton? carton;
CartonEditor({this.carton});
2020-06-04 01:36:49 +06:30
@override
2020-10-19 05:13:49 +06:30
_CartonEditorState createState() => _CartonEditorState();
2020-06-04 01:36:49 +06:30
}
2020-10-19 05:13:49 +06:30
class _CartonEditorState extends State<CartonEditor> {
2024-02-05 11:13:12 +06:30
List<String> _cartonTypes = [carton_from_packages, carton_mix_carton];
2024-02-01 18:07:40 +06:30
List<Carton> _cartons = [];
2020-06-04 01:36:49 +06:30
bool _isLoading = false;
2021-09-10 12:00:08 +06:30
bool _isNew = false;
2024-02-06 17:45:36 +06:30
String _billToValue = billToSender;
2021-09-10 12:00:08 +06:30
String? _selectedCartonType;
2021-01-09 19:11:47 +06:30
2024-02-05 11:13:12 +06:30
User? _consignee;
User? _sender;
2024-02-01 18:07:40 +06:30
Carton? _carton;
2021-01-25 16:09:41 +06:30
2020-06-04 01:36:49 +06:30
@override
void initState() {
2024-02-05 11:13:12 +06:30
_init();
2020-06-04 01:36:49 +06:30
super.initState();
2024-02-05 11:13:12 +06:30
}
2020-10-14 16:53:16 +06:30
2024-02-05 11:13:12 +06:30
_init() {
2021-09-13 09:51:55 +06:30
if (widget.carton != null) {
_carton = widget.carton;
2021-09-10 12:00:08 +06:30
_selectedCartonType = _carton!.cartonType;
2021-01-12 16:59:52 +06:30
2020-10-19 05:13:49 +06:30
_isNew = false;
2024-02-01 18:07:40 +06:30
2024-02-05 11:13:12 +06:30
_consignee = User(
2021-09-10 12:00:08 +06:30
id: _carton!.userID, fcsID: _carton!.fcsID, name: _carton!.userName);
2024-02-05 11:13:12 +06:30
_sender = User(
2021-09-10 12:00:08 +06:30
id: _carton!.senderID,
fcsID: _carton!.senderFCSID,
name: _carton!.senderName);
2020-06-04 01:36:49 +06:30
} else {
2024-02-01 18:07:40 +06:30
_carton = Carton(cargoTypes: [], packages: []);
2020-10-19 05:13:49 +06:30
_isNew = true;
2020-10-14 16:53:16 +06:30
_selectedCartonType = carton_from_packages;
2024-02-01 18:07:40 +06:30
_cartons = [
Carton(cartonNumber: "A177(A)-3#2", cartonWeight: 35.5),
Carton(cartonNumber: "A177(A)-3#1", cartonWeight: 25.5)
];
2024-02-05 11:13:12 +06:30
_sender = User(
name: "ptd-phyo44 kaelone",
fcsID: "FCS-8X6V",
phoneNumber: "+959444444444",
id: "48u_4s-HiQeW-HwSqeRd9TSMWh3mLZfSk5rpaUEh_zw");
_consignee = User(
id: "HsIwG88K-0_HSazgEy5QR27kcjkOvfv7_Sr1JP18Q1A",
name: "One One",
phoneNumber: "+959111111111",
fcsID: "FCS-EFRF");
}
if (mounted) {
setState(() {});
2020-06-04 01:36:49 +06:30
}
}
@override
Widget build(BuildContext context) {
2021-01-09 19:11:47 +06:30
bool isFromPackages = _selectedCartonType == carton_from_packages;
2020-12-02 20:55:00 +06:30
2024-02-01 18:07:40 +06:30
final createBtn = Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
alignment: Alignment.bottomRight,
height: 45,
width: 130,
decoration: BoxDecoration(
color: primaryColor,
borderRadius: BorderRadius.circular(5),
),
child: TextButton(
onPressed: null,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Flexible(
child: LocalText(context, 'box.done.btn',
color: Colors.white, fontSize: 15),
),
const SizedBox(width: 5),
const Icon(
MaterialCommunityIcons.check_circle_outline,
color: Colors.white,
),
],
),
),
2020-12-02 20:55:00 +06:30
)),
2024-02-01 18:07:40 +06:30
],
2020-10-14 16:53:16 +06:30
);
2020-10-19 05:13:49 +06:30
final cartonTypeBox = LocalRadioButtons(
2020-10-20 06:19:10 +06:30
readOnly: !_isNew,
2024-02-05 11:13:12 +06:30
values: _cartonTypes,
2020-10-19 05:13:49 +06:30
selectedValue: _selectedCartonType,
2021-09-10 12:00:08 +06:30
callback: (String? v) {
2020-10-19 05:13:49 +06:30
setState(() {
_selectedCartonType = v;
});
});
2020-10-09 17:28:42 +06:30
2024-02-01 18:07:40 +06:30
final cartonTitleBox = LocalTitle(
textKey: _cartons.isEmpty ? "box.shipment.boxes" : "box.cartion.count",
translationVariables: _cartons.isEmpty ? null : ["${_cartons.length}"],
trailing: Padding(
padding: const EdgeInsets.only(right: 5),
child: InkResponse(
radius: 30,
onTap: () {
//for packages
if (isFromPackages) {
2024-02-05 11:13:12 +06:30
if (_sender == null) {
showMsgDialog(
context, "Error", "Please select sender's FCS ID");
return;
}
if (_consignee == null) {
showMsgDialog(
context, "Error", "Please select consignee's FCS ID");
return;
}
Navigator.push(
context,
CupertinoPageRoute(
builder: (context) => CartonEditorForPackage(
2024-02-06 17:45:36 +06:30
sender: _sender!, consignee: _consignee!,billToValue: _billToValue)));
2024-02-01 18:07:40 +06:30
}
// for mix cartion
else {
2024-02-02 18:00:51 +06:30
Navigator.push(
2024-02-01 18:07:40 +06:30
context,
CupertinoPageRoute(
builder: (context) => const MixCartonEditor()));
}
},
child: Icon(
2020-12-10 20:06:15 +06:30
Icons.add_circle,
color: primaryColor,
),
),
2024-02-01 18:07:40 +06:30
));
2021-01-09 19:11:47 +06:30
2024-02-01 18:07:40 +06:30
final consigneeSearchBox = Row(
2021-01-09 19:11:47 +06:30
children: <Widget>[
2024-02-01 18:07:40 +06:30
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 2),
child: LocalText(context, "box.consignee.title",
color: Colors.black, fontSize: 15),
2021-01-09 19:11:47 +06:30
)),
IconButton(
2024-02-01 18:07:40 +06:30
icon: Icon(Icons.search, color: Colors.black),
2021-01-10 15:56:27 +06:30
onPressed: () => searchUser(context, onUserSelect: (u) {
2021-01-09 19:11:47 +06:30
setState(() {
2024-02-05 11:13:12 +06:30
this._consignee = u;
2021-01-09 19:11:47 +06:30
});
2021-01-10 15:56:27 +06:30
}, popPage: true)),
2021-01-09 19:11:47 +06:30
],
);
2024-02-01 18:07:40 +06:30
final consigneefcsIDBox = DisplayText(
2024-02-05 11:13:12 +06:30
text: _consignee != null ? _consignee!.fcsID : "",
2024-02-01 18:07:40 +06:30
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
2021-01-09 19:11:47 +06:30
);
2024-02-01 18:07:40 +06:30
final consigneePhoneBox = DisplayText(
2024-02-05 11:13:12 +06:30
text: _consignee != null ? _consignee!.phoneNumber : "",
2024-02-01 18:07:40 +06:30
labelTextKey: "processing.phone",
iconData: MaterialCommunityIcons.phone);
final consigneeNameBox = DisplayText(
2024-02-05 11:13:12 +06:30
text: _consignee != null ? _consignee!.name : "",
2024-02-01 18:07:40 +06:30
labelTextKey: "processing.consignee.name",
maxLines: 2,
iconData: MaterialCommunityIcons.account_arrow_left);
2021-01-09 19:11:47 +06:30
final consigneeBox = Container(
child: Column(
children: [
2024-02-01 18:07:40 +06:30
consigneeSearchBox,
2021-01-09 19:11:47 +06:30
consigneefcsIDBox,
2024-02-01 18:07:40 +06:30
consigneePhoneBox,
consigneeNameBox
2021-01-09 19:11:47 +06:30
],
),
);
2024-02-01 18:07:40 +06:30
final senderSearchBox = Row(
2021-01-09 19:11:47 +06:30
children: <Widget>[
2024-02-01 18:07:40 +06:30
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 2),
child: LocalText(context, "box.sender.title",
color: Colors.black, fontSize: 15),
2021-01-09 19:11:47 +06:30
)),
IconButton(
2024-02-01 18:07:40 +06:30
icon: Icon(Icons.search, color: Colors.black),
2021-01-10 15:56:27 +06:30
onPressed: () => searchUser(context, onUserSelect: (u) {
2021-01-09 19:11:47 +06:30
setState(() {
2024-02-05 11:13:12 +06:30
this._sender = u;
2021-01-09 19:11:47 +06:30
});
2021-01-10 15:56:27 +06:30
}, popPage: true)),
2021-01-09 19:11:47 +06:30
],
);
2024-02-01 18:07:40 +06:30
final senderIDBox = DisplayText(
2024-02-05 11:13:12 +06:30
text: _sender != null ? _sender!.fcsID : "",
2024-02-01 18:07:40 +06:30
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon());
final senderPhoneBox = DisplayText(
2024-02-05 11:13:12 +06:30
text: _sender != null ? _sender!.phoneNumber : "",
2024-02-01 18:07:40 +06:30
labelTextKey: "processing.phone",
iconData: MaterialCommunityIcons.phone,
2021-01-09 19:11:47 +06:30
);
2024-02-01 18:07:40 +06:30
final senderNameBox = DisplayText(
2024-02-05 11:13:12 +06:30
text: _sender != null ? _sender!.name : "",
2024-02-01 18:07:40 +06:30
labelTextKey: "processing.shipper.name",
maxLines: 2,
iconData: MaterialCommunityIcons.account_arrow_right);
final senderBox = Container(
2021-01-09 19:11:47 +06:30
child: Column(
children: [
2024-02-01 18:07:40 +06:30
senderSearchBox,
senderIDBox,
senderPhoneBox,
senderNameBox,
2021-01-09 19:11:47 +06:30
],
),
);
2024-02-01 18:07:40 +06:30
final billRadioBox = Container(
2020-12-01 19:02:21 +06:30
child: Row(
children: [
2024-02-01 18:07:40 +06:30
Flexible(
child: InkWell(
onTap: () {
setState(() {
2024-02-06 17:45:36 +06:30
_billToValue = billToSender;
2024-02-01 18:07:40 +06:30
});
},
child: Row(children: <Widget>[
2024-02-02 18:00:51 +06:30
LocalRadio(
2024-02-06 17:45:36 +06:30
value: billToSender,
2024-02-02 18:00:51 +06:30
groupValue: _billToValue,
onChanged: (p0) {
2024-02-01 18:07:40 +06:30
setState(() {
2024-02-06 17:45:36 +06:30
_billToValue = billToSender;
2024-02-01 18:07:40 +06:30
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to_sender',
2024-02-02 18:00:51 +06:30
fontSize: 15,
2024-02-06 17:45:36 +06:30
color: _billToValue == billToSender ? primaryColor : Colors.black),
2020-12-01 19:02:21 +06:30
),
2024-02-01 18:07:40 +06:30
)
]),
)),
Flexible(
child: InkWell(
onTap: () {
setState(() {
2024-02-06 17:45:36 +06:30
_billToValue = billToConsignee;
2024-02-01 18:07:40 +06:30
});
},
child: Row(children: <Widget>[
2024-02-02 18:00:51 +06:30
LocalRadio(
2024-02-06 17:45:36 +06:30
value: billToConsignee,
2024-02-02 18:00:51 +06:30
groupValue: _billToValue,
onChanged: (p0) {
2020-12-01 19:02:21 +06:30
setState(() {
2024-02-06 17:45:36 +06:30
_billToValue = billToConsignee;
2020-12-01 19:02:21 +06:30
});
},
),
2024-02-01 18:07:40 +06:30
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to.consignee',
2024-02-02 18:00:51 +06:30
fontSize: 15,
2024-02-06 17:45:36 +06:30
color: _billToValue == billToConsignee ? primaryColor : Colors.black),
2024-02-01 18:07:40 +06:30
),
)
]),
2020-12-01 19:02:21 +06:30
),
2024-02-01 18:07:40 +06:30
)
2020-12-01 19:02:21 +06:30
],
),
);
2024-02-01 18:07:40 +06:30
return LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: LocalAppBar(
labelKey: _isNew ? "boxes.new" : "box.edit.title",
backgroundColor: Colors.white,
arrowColor: primaryColor,
labelColor: primaryColor),
body: ListView(
padding: EdgeInsets.only(left: 10, right: 10),
shrinkWrap: true,
children: [
LocalTitle(textKey: "box.select.carton_type"),
cartonTypeBox,
isFromPackages
? Column(
children: [
LocalTitle(textKey: "box.select.sender_and_consignee"),
Row(
children: [
Flexible(child: senderBox),
Flexible(child: consigneeBox)
],
),
2024-02-02 18:00:51 +06:30
const SizedBox(height: 5),
billRadioBox,
const SizedBox(height: 5),
2024-02-01 18:07:40 +06:30
],
)
: Container(),
cartonTitleBox,
Column(children: _getCartons(context, _cartons)),
SizedBox(height: 20),
createBtn,
SizedBox(height: 20),
],
),
),
2020-12-01 19:02:21 +06:30
);
}
2024-02-01 18:07:40 +06:30
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
return cartons.asMap().entries.map((c) {
return InkWell(onTap: () async {}, child: CartonRow(box: c.value));
}).toList();
2020-10-19 05:13:49 +06:30
}
2020-06-04 01:36:49 +06:30
}