Files
fcs/lib/pages/rates/custom_list.dart
2025-03-12 17:49:27 +06:30

120 lines
4.0 KiB
Dart

import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/rates/custom_editor.dart';
import 'package:fcs/pages/widgets/local_app_bar.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/progress.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'model/shipment_rate_model.dart';
class CustomList extends StatefulWidget {
final bool? selected;
const CustomList({super.key, this.selected});
@override
_CustomListState createState() => _CustomListState();
}
class _CustomListState extends State<CustomList> {
bool isLoading = false;
bool _selected = false;
@override
void initState() {
super.initState();
if (widget.selected != null) {
_selected = widget.selected!;
}
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
var shipmentRateModel = Provider.of<ShipmentRateModel>(context);
return LocalProgress(
inAsyncCall: isLoading,
child: Scaffold(
appBar: LocalAppBar(labelKey: 'rate.custom_duty.title'),
floatingActionButton: FloatingActionButton.extended(
onPressed: () {
Navigator.of(context).push(
CupertinoPageRoute(builder: (context) => CustomEditor()));
},
icon: Icon(Icons.add, color: Colors.white),
backgroundColor: primaryColor,
label:
LocalText(context, 'rate.custom_new', color: Colors.white)),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView.separated(
separatorBuilder: (c, i) => Divider(
color: primaryColor,
),
itemCount: shipmentRateModel.rate.customDuties.length,
itemBuilder: (context, index) {
CargoType custom = shipmentRateModel.rate.customDuties[index];
return InkWell(
onTap: () {
_selected
? Navigator.pop(context, custom)
: Navigator.of(context).push(CupertinoPageRoute(
builder: (context) =>
CustomEditor(custom: custom)));
},
child: Container(
child: _row(
custom.name ?? "",
"Custom Fee \$ ${custom.customDutyFee.toStringAsFixed(2)}",
// ignore: unnecessary_null_comparison
custom.rate == null
? ""
: "Shipment rate \$ ${custom.rate.toStringAsFixed(2)}"),
),
);
}),
)),
);
}
_row(String desc, String fee, String shipmentRate) {
return Container(
padding: EdgeInsets.only(left: 25, top: 5, bottom: 5),
child: Row(
children: <Widget>[
Text('$desc ', style: TextStyle(fontSize: 15)),
Spacer(),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(bottom: 3.0),
child: Text(
fee,
style: TextStyle(color: primaryColor, fontSize: 14),
),
),
shipmentRate == ""
? Container()
: Padding(
padding: const EdgeInsets.only(top: 3.0),
child: Text(
shipmentRate,
style: TextStyle(color: Colors.grey, fontSize: 14),
),
)
],
),
SizedBox(
width: 50,
),
],
));
}
}