Files
fcs/lib/pages/carton/mix_carton/mix_carton_editor.dart

202 lines
5.6 KiB
Dart
Raw Normal View History

2024-02-02 18:00:51 +06:30
// ignore_for_file: deprecated_member_use
2024-02-01 18:07:40 +06:30
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
2024-02-02 18:00:51 +06:30
import 'package:provider/provider.dart';
2024-02-01 18:07:40 +06:30
2024-02-02 18:00:51 +06:30
import '../../../domain/constants.dart';
import '../../../domain/entities/carton.dart';
import '../../../domain/entities/carton_size.dart';
import '../../../domain/entities/fcs_shipment.dart';
2024-02-01 18:07:40 +06:30
import '../../../domain/vo/local_step.dart';
import '../../../helpers/theme.dart';
2024-02-05 11:13:12 +06:30
import '../../main/util.dart';
2024-02-01 18:07:40 +06:30
import '../../widgets/local_text.dart';
import '../../widgets/progress.dart';
import '../../widgets/step_widget.dart';
2024-02-02 18:00:51 +06:30
import '../model/carton_selection_model.dart';
import 'carton_selection_widget.dart';
2024-02-05 11:13:12 +06:30
import 'mix_carton_submit.dart';
2024-02-01 18:07:40 +06:30
import 'type_widget.dart';
class MixCartonEditor extends StatefulWidget {
const MixCartonEditor({
Key? key,
}) : super(key: key);
@override
State<MixCartonEditor> createState() => _MixCartonEditorState();
}
class _MixCartonEditorState extends State<MixCartonEditor> {
var dateFormatter = DateFormat('dd MMM yyyy');
final NumberFormat numberFormatter = NumberFormat("#,###");
List<LocalStep> steps = [
LocalStep(lable: 'Type', stepType: StepType.TYPE),
LocalStep(lable: 'Cartons', stepType: StepType.CARTONS),
LocalStep(lable: 'Submit', stepType: StepType.SUBMIT)
];
2024-02-02 18:00:51 +06:30
List<Carton> _cartions = [];
2024-02-01 18:07:40 +06:30
int currentStep = 0;
2024-02-02 18:00:51 +06:30
double _length = 0;
double _width = 0;
double _height = 0;
FcsShipment? _shipment;
2024-02-05 11:13:12 +06:30
String _cartonSizeType = standardCarton;
2024-02-02 18:00:51 +06:30
CartonSize? _standardSize;
bool _isLoading = false;
2024-02-01 18:07:40 +06:30
@override
void initState() {
2024-02-02 18:00:51 +06:30
context.read<CartonSelectionModel>().clearSelection();
2024-02-01 18:07:40 +06:30
super.initState();
}
@override
Widget build(BuildContext context) {
return WillPopScope(
onWillPop: () {
if (currentStep == 0) {
Navigator.of(context).pop();
}
if (currentStep > 0) {
setState(() {
currentStep -= 1;
});
}
return Future.value(false);
},
child: LocalProgress(
inAsyncCall: _isLoading,
child: Scaffold(
appBar: AppBar(
elevation: 0,
centerTitle: true,
leading: IconButton(
icon: const Icon(CupertinoIcons.back,
color: primaryColor, size: 25),
onPressed: () {
if (currentStep == 0) {
Navigator.of(context).pop();
}
if (currentStep > 0) {
setState(() {
currentStep -= 1;
});
}
},
),
backgroundColor: Colors.white,
title: LocalText(context, 'boxes.new',
color: primaryColor, fontSize: 20),
),
body: Column(
children: [
StepperWidget(
labels: steps.map((e) => e.lable).toList(),
currentStep: currentStep,
2024-02-05 11:13:12 +06:30
eachStepWidth: MediaQuery.of(context).size.width / 3,
2024-02-01 18:07:40 +06:30
onChange: (index) {
if (index > currentStep) {
return;
}
setState(() {
currentStep = index;
});
},
),
getContent(currentStep)
],
))),
);
}
Widget getContent(int index) {
var step = steps[index];
if (step.stepType == StepType.TYPE) {
2024-02-02 18:00:51 +06:30
return Expanded(
child: TypeWidget(
shipment: _shipment,
2024-02-05 11:13:12 +06:30
cartonSizeType: _cartonSizeType,
2024-02-02 18:00:51 +06:30
standardSize: _standardSize,
length: _length,
width: _width,
height: _height,
2024-02-01 18:07:40 +06:30
onPrevious: () {
Navigator.pop(context);
},
2024-02-02 18:00:51 +06:30
onContinue: (shipment, cartonSizeType,
{standardSize, length, width, height}) {
setState(() {
_shipment = shipment;
2024-02-05 11:13:12 +06:30
_cartonSizeType = cartonSizeType;
2024-02-02 18:00:51 +06:30
_standardSize = standardSize;
_length = length ?? 0;
_width = width ?? 0;
_height = height ?? 0;
currentStep += 1;
});
},
2024-02-01 18:07:40 +06:30
));
} else if (step.stepType == StepType.CARTONS) {
return Expanded(
2024-02-02 18:00:51 +06:30
child: CartonSelectionWidget(
shipment: _shipment!,
cartons: _cartions,
onContinue: (cartons) {
setState(() {
_cartions = List.from(cartons);
currentStep += 1;
});
},
onPrevious: (cartons) {
setState(() {
_cartions = List.from(cartons);
currentStep -= 1;
});
},
),
2024-02-01 18:07:40 +06:30
);
} else {
return Expanded(
2024-02-05 11:13:12 +06:30
child: MixCartonSubmit(
cartonSizeType: _cartonSizeType,
standardSize: _standardSize,
length: _length,
width: _width,
height: _height,
shipment: _shipment!,
cartons: _cartions,
onCreate: () {
_create();
},
onPrevious: () {
setState(() {
currentStep -= 1;
});
},
),
2024-02-01 18:07:40 +06:30
);
}
}
2024-02-05 11:13:12 +06:30
_create() async {
setState(() {
_isLoading = true;
});
try {
Navigator.pop(context, true);
} catch (e) {
showMsgDialog(context, "Error", e.toString());
} finally {
setState(() {
_isLoading = false;
});
}
}
2024-02-01 18:07:40 +06:30
}