115 lines
3.0 KiB
Dart
115 lines
3.0 KiB
Dart
import 'package:fcs/domain/entities/cargo_type.dart';
|
|
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:fcs/pages/rates/model/shipment_rate_model.dart';
|
|
import 'package:fcs/pages/widgets/local_app_bar.dart';
|
|
import 'package:fcs/pages/widgets/progress.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../main/util.dart';
|
|
|
|
class SurchargeItemAddition extends StatefulWidget {
|
|
final List<CargoType> items;
|
|
const SurchargeItemAddition({super.key, required this.items});
|
|
@override
|
|
_SurchargeItemAdditionState createState() => _SurchargeItemAdditionState();
|
|
}
|
|
|
|
class _SurchargeItemAdditionState extends State<SurchargeItemAddition> {
|
|
bool _isLoading = false;
|
|
List<CargoType> surchargeItems = [];
|
|
|
|
@override
|
|
void initState() {
|
|
_init();
|
|
super.initState();
|
|
}
|
|
|
|
_init() {
|
|
var shipmentRateModel =
|
|
Provider.of<ShipmentRateModel>(context, listen: false);
|
|
surchargeItems =
|
|
shipmentRateModel.rate.customDuties.map((e) => e.clone()).toList();
|
|
|
|
for (var p in surchargeItems) {
|
|
p.qty = 0;
|
|
if (widget.items.any((e) => e.id == p.id)) {
|
|
p.isChecked = true;
|
|
} else {
|
|
p.isChecked = false;
|
|
}
|
|
|
|
widget.items.forEach((vp) {
|
|
if (p.id == vp.id) {
|
|
p.qty = vp.qty;
|
|
}
|
|
});
|
|
}
|
|
|
|
if (mounted) {
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
_onTap(CargoType cargo) {
|
|
if (cargo.isChecked) {
|
|
showMsgDialog(context, "Error", "Already exit!");
|
|
return;
|
|
}
|
|
Navigator.pop(context, cargo);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List<Widget> getCargoRowList(List<CargoType> _c) {
|
|
return _c.map((c) {
|
|
return ListTile(
|
|
onTap: () {
|
|
_onTap(c);
|
|
},
|
|
title: new Text(c.name ?? '', style: textStyle),
|
|
trailing: ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: primaryColor,
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(5),
|
|
),
|
|
minimumSize: Size(80, 35)),
|
|
onPressed: c.isChecked
|
|
? null
|
|
: () {
|
|
_onTap(c);
|
|
},
|
|
child: Text(
|
|
"Add",
|
|
style: TextStyle(color: Colors.white, fontSize: 14),
|
|
),
|
|
));
|
|
}).toList();
|
|
}
|
|
|
|
return LocalProgress(
|
|
inAsyncCall: _isLoading,
|
|
child: Scaffold(
|
|
appBar: LocalAppBar(
|
|
labelKey: 'box.select.cargo_type',
|
|
backgroundColor: Colors.white,
|
|
labelColor: primaryColor,
|
|
arrowColor: primaryColor),
|
|
body: Container(
|
|
padding: EdgeInsets.all(10),
|
|
child: ListView(
|
|
shrinkWrap: true,
|
|
children: <Widget>[
|
|
Column(
|
|
children: getCargoRowList(surchargeItems),
|
|
),
|
|
SizedBox(height: 30),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|