Files
fcs/lib/pages/carton/carton_editor.dart
2024-02-01 18:07:40 +06:30

351 lines
11 KiB
Dart

import 'package:fcs/domain/constants.dart';
import 'package:fcs/domain/entities/carton.dart';
import 'package:fcs/domain/entities/user.dart';
import 'package:fcs/helpers/theme.dart';
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';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/local_radio_buttons.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/local_title.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 'mix_cation/mix_cartion_editor.dart';
import 'carton_row.dart';
class CartonEditor extends StatefulWidget {
final Carton? carton;
CartonEditor({this.carton});
@override
_CartonEditorState createState() => _CartonEditorState();
}
class _CartonEditorState extends State<CartonEditor> {
List<String> cartonTypes = [carton_from_packages, carton_mix_carton];
List<Carton> _cartons = [];
bool _isLoading = false;
bool _isNew = false;
int _billToValue = 1;
String? _selectedCartonType;
User? consignee;
User? sender;
Carton? _carton;
@override
void initState() {
super.initState();
if (widget.carton != null) {
_carton = widget.carton;
_selectedCartonType = _carton!.cartonType;
_isNew = false;
consignee = User(
id: _carton!.userID, fcsID: _carton!.fcsID, name: _carton!.userName);
sender = User(
id: _carton!.senderID,
fcsID: _carton!.senderFCSID,
name: _carton!.senderName);
} else {
_carton = Carton(cargoTypes: [], packages: []);
_isNew = true;
_selectedCartonType = carton_from_packages;
_cartons = [
Carton(cartonNumber: "A177(A)-3#2", cartonWeight: 35.5),
Carton(cartonNumber: "A177(A)-3#1", cartonWeight: 25.5)
];
}
}
@override
Widget build(BuildContext context) {
bool isFromPackages = _selectedCartonType == carton_from_packages;
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,
),
],
),
),
)),
],
);
final cartonTypeBox = LocalRadioButtons(
readOnly: !_isNew,
values: cartonTypes,
selectedValue: _selectedCartonType,
callback: (String? v) {
setState(() {
_selectedCartonType = v;
});
});
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(
Icons.add_circle,
color: primaryColor,
),
),
));
final consigneeSearchBox = Row(
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 2),
child: LocalText(context, "box.consignee.title",
color: Colors.black, fontSize: 15),
)),
IconButton(
icon: Icon(Icons.search, color: Colors.black),
onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() {
this.consignee = u;
});
}, popPage: true)),
],
);
final consigneefcsIDBox = DisplayText(
text: consignee != null ? consignee!.fcsID : "",
labelTextKey: "processing.fcs.id",
icon: FcsIDIcon(),
);
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);
final consigneeBox = Container(
child: Column(
children: [
consigneeSearchBox,
consigneefcsIDBox,
consigneePhoneBox,
consigneeNameBox
],
),
);
final senderSearchBox = Row(
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 2),
child: LocalText(context, "box.sender.title",
color: Colors.black, fontSize: 15),
)),
IconButton(
icon: Icon(Icons.search, color: Colors.black),
onPressed: () => searchUser(context, onUserSelect: (u) {
setState(() {
this.sender = u;
});
}, popPage: true)),
],
);
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,
);
final senderNameBox = DisplayText(
text: sender != null ? sender!.name : "",
labelTextKey: "processing.shipper.name",
maxLines: 2,
iconData: MaterialCommunityIcons.account_arrow_right);
final senderBox = Container(
child: Column(
children: [
senderSearchBox,
senderIDBox,
senderPhoneBox,
senderNameBox,
],
),
);
final billRadioBox = Container(
child: Row(
children: [
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),
),
)
]),
)),
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) {
setState(() {
_billToValue = 2;
});
},
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(left: 10),
child: LocalText(context, 'box.bill_to.consignee',
fontSize: 14,
color: _billToValue == 2 ? primaryColor : Colors.black),
),
)
]),
),
)
],
),
);
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),
],
),
),
);
}
List<Widget> _getCartons(BuildContext context, List<Carton> cartons) {
return cartons.asMap().entries.map((c) {
return InkWell(onTap: () async {}, child: CartonRow(box: c.value));
}).toList();
}
}