add carton editor for package
This commit is contained in:
127
lib/pages/carton/custom_duty_addition.dart
Normal file
127
lib/pages/carton/custom_duty_addition.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
import 'package:fcs/domain/entities/cargo_type.dart';
|
||||
import 'package:fcs/helpers/theme.dart';
|
||||
import 'package:fcs/pages/main/util.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/local_title.dart';
|
||||
import 'package:fcs/pages/widgets/progress.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../widgets/local_button.dart';
|
||||
|
||||
class CustomDutyAddition extends StatefulWidget {
|
||||
final List<CargoType> customDuties;
|
||||
|
||||
const CustomDutyAddition({super.key, required this.customDuties});
|
||||
@override
|
||||
_CustomDutyAdditionState createState() => _CustomDutyAdditionState();
|
||||
}
|
||||
|
||||
class _CustomDutyAdditionState extends State<CustomDutyAddition> {
|
||||
bool _isLoading = false;
|
||||
List<CargoType> customDuties = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_init();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
_init() {
|
||||
var shipmentRateModel =
|
||||
Provider.of<ShipmentRateModel>(context, listen: false);
|
||||
customDuties =
|
||||
shipmentRateModel.rate.customDuties.map((e) => e.clone()).toList();
|
||||
|
||||
for (var p in customDuties) {
|
||||
if (widget.customDuties.any((e) => e.id == p.id)) {
|
||||
p.isChecked = true;
|
||||
} else {
|
||||
p.isChecked = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Widget> getCargoRowList(List<CargoType> _c) {
|
||||
return _c.map((c) {
|
||||
return Container(
|
||||
child: Container(
|
||||
padding:
|
||||
EdgeInsets.only(left: 10.0, right: 5.0, top: 3.0, bottom: 3.0),
|
||||
child: InkWell(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
c.isChecked = !c.isChecked;
|
||||
});
|
||||
},
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: c.isChecked,
|
||||
activeColor: primaryColor,
|
||||
onChanged: (bool? check) {
|
||||
setState(() {
|
||||
c.isChecked = check ?? false;
|
||||
});
|
||||
}),
|
||||
new Text(c.name ?? '', style: textStyle),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
final saveBtn = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 30),
|
||||
child: LocalButton(
|
||||
textKey: "box.cargo.select.btn",
|
||||
callBack: () {
|
||||
List<CargoType> _cargos =
|
||||
customDuties.where((c) => c.isChecked).toList();
|
||||
if (_cargos.isEmpty) {
|
||||
showMsgDialog(context, 'Error', "Please select the cargo type");
|
||||
return;
|
||||
}
|
||||
Navigator.pop(context, _cargos);
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
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>[
|
||||
LocalTitle(
|
||||
textKey: "box.select.cargo.title",
|
||||
),
|
||||
Column(
|
||||
children: getCargoRowList(customDuties),
|
||||
),
|
||||
SizedBox(height: 30),
|
||||
saveBtn,
|
||||
SizedBox(height: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user