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 customDuties; const CustomDutyAddition({super.key, required this.customDuties}); @override _CustomDutyAdditionState createState() => _CustomDutyAdditionState(); } class _CustomDutyAdditionState extends State { bool _isLoading = false; List customDuties = []; @override void initState() { _init(); super.initState(); } _init() { var shipmentRateModel = Provider.of(context, listen: false); customDuties = shipmentRateModel.rate.customDuties.map((e) => e.clone()).toList(); for (var p in customDuties) { p.qty = 0; if (widget.customDuties.any((e) => e.id == p.id)) { p.isChecked = true; } else { p.isChecked = false; } widget.customDuties.forEach((vp) { if (p.id == vp.id) { p.qty = vp.qty; } }); } if (mounted) { setState(() {}); } } @override Widget build(BuildContext context) { List getCargoRowList(List _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: [ 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 _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: [ LocalTitle( textKey: "box.select.cargo.title", ), Column( children: getCargoRowList(customDuties), ), SizedBox(height: 30), saveBtn, SizedBox(height: 20), ], ), ), ), ); } }