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

351 lines
11 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';
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-01 18:07:40 +06:30
import 'mix_cation/mix_cartion_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-01 18:07:40 +06:30
List<String> cartonTypes = [carton_from_packages, carton_mix_carton];
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-01 18:07:40 +06:30
int _billToValue = 1;
2021-09-10 12:00:08 +06:30
String? _selectedCartonType;
2021-01-09 19:11:47 +06:30
2021-09-10 12:00:08 +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() {
super.initState();
2020-10-14 16:53:16 +06:30
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
2021-01-10 15:56:27 +06:30
consignee = User(
2021-09-10 12:00:08 +06:30
id: _carton!.userID, fcsID: _carton!.fcsID, name: _carton!.userName);
2021-01-10 15:56:27 +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)
];
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-01 18:07:40 +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) {
}
// for mix cartion
else {
Navigator.push(
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(() {
this.consignee = u;
});
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(
text: consignee != null ? consignee!.fcsID : "",
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(
text: consignee != null ? consignee!.phoneNumber : "",
labelTextKey: "processing.phone",
iconData: MaterialCommunityIcons.phone);
final consigneeNameBox = DisplayText(
text: consignee != null ? consignee!.name : "",
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(() {
this.sender = u;
});
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(
text: sender != null ? sender!.fcsID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon());
final senderPhoneBox = DisplayText(
text: sender != null ? sender!.phoneNumber : "",
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(
text: sender != null ? sender!.name : "",
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(() {
_billToValue = 1;
});
},
child: Row(children: <Widget>[
Radio(
visualDensity: const VisualDensity(
horizontal: VisualDensity.minimumDensity),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
activeColor: primaryColor,
groupValue: _billToValue,
value: 1,
onChanged: (value) {
setState(() {
_billToValue = 1;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to_sender',
fontSize: 14,
color: _billToValue == 1 ? primaryColor : Colors.black),
2020-12-01 19:02:21 +06:30
),
2024-02-01 18:07:40 +06:30
)
]),
)),
Flexible(
child: InkWell(
onTap: () {
setState(() {
_billToValue = 2;
});
},
child: Row(children: <Widget>[
Radio(
visualDensity: const VisualDensity(
horizontal: VisualDensity.minimumDensity),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
activeColor: primaryColor,
groupValue: _billToValue,
value: 2,
onChanged: (value) {
2020-12-01 19:02:21 +06:30
setState(() {
2024-02-01 18:07:40 +06:30
_billToValue = 2;
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',
fontSize: 14,
color: _billToValue == 2 ? primaryColor : Colors.black),
),
)
]),
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)
],
),
billRadioBox
],
)
: 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
}