Files
fcs/lib/pages/carton/cargo_table.dart

120 lines
3.0 KiB
Dart
Raw Normal View History

2020-12-10 20:06:15 +06:30
import 'package:fcs/domain/entities/cargo_type.dart';
import 'package:fcs/helpers/theme.dart';
import 'package:fcs/pages/widgets/local_text.dart';
import 'package:fcs/pages/widgets/my_data_table.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class CargoTable extends StatefulWidget {
2021-09-10 12:00:08 +06:30
final List<CargoType>? cargoTypes;
2020-12-10 20:06:15 +06:30
const CargoTable({
2021-09-10 12:00:08 +06:30
Key? key,
2020-12-10 20:06:15 +06:30
this.cargoTypes,
}) : super(key: key);
@override
_CargoTableState createState() => _CargoTableState();
}
class _CargoTableState extends State<CargoTable> {
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
2021-09-13 11:09:32 +06:30
child: DataTable(
2020-12-10 20:06:15 +06:30
headingRowHeight: 40,
2020-12-11 17:34:56 +06:30
columnSpacing: 50,
2021-09-13 11:09:32 +06:30
showCheckboxColumn: false,
2020-12-10 20:06:15 +06:30
columns: [
2021-09-13 11:09:32 +06:30
DataColumn(
2020-12-10 20:06:15 +06:30
label: LocalText(
context,
"cargo.type",
color: Colors.grey,
),
),
2021-09-13 11:09:32 +06:30
DataColumn(
2020-12-11 17:34:56 +06:30
label: LocalText(
context,
"cargo.qty",
color: Colors.grey,
),
),
2021-09-13 11:09:32 +06:30
DataColumn(
2020-12-10 20:06:15 +06:30
label: LocalText(
context,
"cargo.weight",
color: Colors.grey,
),
),
],
rows: getCargoRows(context),
),
);
}
2021-09-13 11:09:32 +06:30
List<DataRow> getCargoRows(BuildContext context) {
2020-12-10 20:06:15 +06:30
if (widget.cargoTypes == null) {
return [];
}
double total = 0;
2021-09-10 12:00:08 +06:30
var rows = widget.cargoTypes!.map((c) {
2021-09-10 16:33:52 +06:30
total += c.weight;
2021-09-13 11:09:32 +06:30
return DataRow(
onSelectChanged: (bool? selected) async {},
2020-12-10 20:06:15 +06:30
cells: [
2021-09-13 11:09:32 +06:30
DataCell(new Text(
2021-09-10 12:00:08 +06:30
c.name ?? "",
2020-12-10 20:06:15 +06:30
style: textStyle,
)),
2021-09-13 11:09:32 +06:30
DataCell(c.qty == null || c.qty == 0
2020-12-11 17:34:56 +06:30
? Center(
child: Text(
"-",
style: textStyle,
),
)
: Center(
child: Text(
c.qty.toString(),
style: textStyle,
),
)),
2021-09-13 11:09:32 +06:30
DataCell(
2021-09-10 16:33:52 +06:30
Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2),
2020-12-10 20:06:15 +06:30
style: textStyle),
),
],
);
}).toList();
2021-09-13 11:09:32 +06:30
var totalRow = DataRow(
onSelectChanged: (bool? selected) {},
2020-12-10 20:06:15 +06:30
cells: [
2021-09-13 11:09:32 +06:30
DataCell(Align(
2020-12-10 20:06:15 +06:30
alignment: Alignment.centerRight,
child: LocalText(
context,
"shipment.cargo.total",
color: Colors.black87,
fontWeight: FontWeight.bold,
),
)),
2021-09-13 11:09:32 +06:30
DataCell(Text("")),
DataCell(
2020-12-10 20:06:15 +06:30
Padding(
padding: const EdgeInsets.only(right: 48.0),
child: Align(
alignment: Alignment.centerRight,
child: Text(total.toStringAsFixed(2),
style: TextStyle(fontWeight: FontWeight.bold))),
),
),
],
);
rows.add(totalRow);
return rows;
}
}