update pages for carton
This commit is contained in:
@@ -3,8 +3,6 @@ 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_search.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';
|
||||
@@ -22,24 +20,22 @@ import 'model/package_selection_model.dart';
|
||||
import 'widget/carton_row.dart';
|
||||
|
||||
class CartonEditor extends StatefulWidget {
|
||||
final Carton? carton;
|
||||
CartonEditor({this.carton});
|
||||
const CartonEditor({super.key});
|
||||
|
||||
@override
|
||||
_CartonEditorState createState() => _CartonEditorState();
|
||||
}
|
||||
|
||||
class _CartonEditorState extends State<CartonEditor> {
|
||||
List<String> _cartonTypes = [carton_from_packages, carton_mix_carton];
|
||||
List<Carton> _cartons = [];
|
||||
List<String> cartonTypes = [carton_from_packages, carton_mix_carton];
|
||||
List<Carton> cartons = [];
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _isNew = false;
|
||||
bool isLoading = false;
|
||||
String? _selectedCartonType;
|
||||
|
||||
User? _consignee;
|
||||
User? _sender;
|
||||
Carton? _carton;
|
||||
|
||||
bool _hasPackages = true;
|
||||
|
||||
@override
|
||||
@@ -49,26 +45,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
}
|
||||
|
||||
_init() {
|
||||
if (widget.carton != null) {
|
||||
_carton = widget.carton;
|
||||
_selectedCartonType = _carton!.cartonType;
|
||||
|
||||
_isNew = false;
|
||||
|
||||
_consignee = User(
|
||||
id: _carton!.consigneeID,
|
||||
fcsID: _carton!.consigneeFCSID,
|
||||
name: _carton!.consigneeName);
|
||||
_sender = User(
|
||||
id: _carton!.senderID,
|
||||
fcsID: _carton!.senderFCSID,
|
||||
name: _carton!.senderName);
|
||||
} else {
|
||||
_carton = Carton(cargoTypes: [], packages: []);
|
||||
_isNew = true;
|
||||
_selectedCartonType = carton_from_packages;
|
||||
_cartons = [];
|
||||
}
|
||||
_selectedCartonType = carton_from_packages;
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
@@ -115,8 +92,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
);
|
||||
|
||||
final cartonTypeBox = LocalRadioButtons(
|
||||
readOnly: !_isNew,
|
||||
values: _cartonTypes,
|
||||
readOnly: false,
|
||||
values: cartonTypes,
|
||||
selectedValue: _selectedCartonType,
|
||||
callback: (String? v) {
|
||||
setState(() {
|
||||
@@ -125,8 +102,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
});
|
||||
|
||||
final cartonTitleBox = LocalTitle(
|
||||
textKey: _cartons.isEmpty ? "box.shipment.boxes" : "box.cartion.count",
|
||||
translationVariables: _cartons.isEmpty ? null : ["${_cartons.length}"],
|
||||
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(
|
||||
@@ -134,20 +111,19 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
onTap: () async {
|
||||
//for packages
|
||||
if (isFromPackages) {
|
||||
if (_sender == null) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please select sender's FCS ID");
|
||||
if (_consignee == null) {
|
||||
showMsgDialog(context, "Error", "Please select consignee");
|
||||
return;
|
||||
}
|
||||
if (_consignee == null) {
|
||||
showMsgDialog(
|
||||
context, "Error", "Please select consignee's FCS ID");
|
||||
|
||||
if (_sender == null) {
|
||||
showMsgDialog(context, "Error", "Please select sender");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_hasPackages) {
|
||||
showMsgDialog(
|
||||
context, "Error", "No packages in sender and consignee");
|
||||
context, "Error", "No packages in consignee and sender");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,13 +131,11 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
context,
|
||||
CupertinoPageRoute(
|
||||
builder: (context) => CartonPackageForm(
|
||||
sender: _sender!,
|
||||
consignee: _consignee!,
|
||||
)));
|
||||
sender: _sender!, consignee: _consignee!)));
|
||||
|
||||
if (carton != null) {
|
||||
setState(() {
|
||||
_cartons.add(carton);
|
||||
cartons.add(carton);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -174,7 +148,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
|
||||
if (carton != null) {
|
||||
setState(() {
|
||||
_cartons.add(carton);
|
||||
cartons.add(carton);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -183,109 +157,33 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
),
|
||||
));
|
||||
|
||||
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) async {
|
||||
setState(() {
|
||||
this._consignee = u;
|
||||
});
|
||||
final consigneeBox = userSearchBox(context,
|
||||
lableKey: 'box.consignee.title',
|
||||
icon: MaterialCommunityIcons.account_arrow_left,
|
||||
user: _consignee,
|
||||
onSearch: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
_consignee = u;
|
||||
});
|
||||
_checkPackages();
|
||||
}, popPage: true));
|
||||
|
||||
_checkPackages();
|
||||
}, 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(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
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) async {
|
||||
setState(() {
|
||||
this._sender = u;
|
||||
});
|
||||
|
||||
_checkPackages();
|
||||
}, 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(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
senderSearchBox,
|
||||
senderIDBox,
|
||||
senderPhoneBox,
|
||||
senderNameBox,
|
||||
],
|
||||
),
|
||||
);
|
||||
final senderBox = userSearchBox(context,
|
||||
lableKey: 'box.sender.title',
|
||||
icon: MaterialCommunityIcons.account_arrow_right,
|
||||
user: _sender,
|
||||
onSearch: () => searchUser(context, onUserSelect: (u) {
|
||||
setState(() {
|
||||
_sender = u;
|
||||
});
|
||||
_checkPackages();
|
||||
}, popPage: true));
|
||||
|
||||
return LocalProgress(
|
||||
inAsyncCall: _isLoading,
|
||||
inAsyncCall: isLoading,
|
||||
child: Scaffold(
|
||||
appBar: LocalAppBar(
|
||||
labelKey: _isNew ? "boxes.new" : "box.edit.title",
|
||||
labelKey: "boxes.new",
|
||||
backgroundColor: Colors.white,
|
||||
arrowColor: primaryColor,
|
||||
labelColor: primaryColor),
|
||||
@@ -303,8 +201,8 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Flexible(child: senderBox),
|
||||
Flexible(child: consigneeBox)
|
||||
Flexible(child: consigneeBox),
|
||||
Flexible(child: senderBox)
|
||||
],
|
||||
),
|
||||
!_hasPackages
|
||||
@@ -319,7 +217,7 @@ class _CartonEditorState extends State<CartonEditor> {
|
||||
)
|
||||
: Container(),
|
||||
cartonTitleBox,
|
||||
Column(children: _getCartons(context, _cartons)),
|
||||
Column(children: _getCartons(context, cartons)),
|
||||
SizedBox(height: 20),
|
||||
createBtn,
|
||||
SizedBox(height: 20),
|
||||
|
||||
Reference in New Issue
Block a user