119 lines
3.0 KiB
Dart
119 lines
3.0 KiB
Dart
import 'package:fcs/domain/entities/cargo_type.dart';
|
|
import 'package:fcs/helpers/theme.dart';
|
|
import 'package:fcs/pages/widgets/local_text.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
class CargoTable extends StatefulWidget {
|
|
final List<CargoType>? cargoTypes;
|
|
|
|
const CargoTable({
|
|
Key? key,
|
|
this.cargoTypes,
|
|
}) : super(key: key);
|
|
|
|
@override
|
|
_CargoTableState createState() => _CargoTableState();
|
|
}
|
|
|
|
class _CargoTableState extends State<CargoTable> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
scrollDirection: Axis.horizontal,
|
|
child: DataTable(
|
|
headingRowHeight: 40,
|
|
columnSpacing: 50,
|
|
showCheckboxColumn: false,
|
|
decoration: BoxDecoration(border: Border.all(color: Colors.white)),
|
|
border: TableBorder(horizontalInside: BorderSide(color: Colors.white)),
|
|
columns: [
|
|
DataColumn(
|
|
label: LocalText(
|
|
context,
|
|
"cargo.type",
|
|
color: Colors.grey,
|
|
),
|
|
),
|
|
DataColumn(
|
|
label: LocalText(
|
|
context,
|
|
"cargo.qty",
|
|
color: Colors.grey,
|
|
),
|
|
),
|
|
DataColumn(
|
|
label: LocalText(
|
|
context,
|
|
"cargo.weight",
|
|
color: Colors.grey,
|
|
),
|
|
),
|
|
],
|
|
rows: getCargoRows(context),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<DataRow> getCargoRows(BuildContext context) {
|
|
if (widget.cargoTypes == null) {
|
|
return [];
|
|
}
|
|
double total = 0;
|
|
var rows = widget.cargoTypes!.map((c) {
|
|
total += c.weight;
|
|
return DataRow(
|
|
onSelectChanged: (bool? selected) async {},
|
|
cells: [
|
|
DataCell(new Text(
|
|
c.name ?? "",
|
|
style: textStyle,
|
|
)),
|
|
DataCell(c.qty == 0
|
|
? Center(
|
|
child: Text(
|
|
"-",
|
|
style: textStyle,
|
|
),
|
|
)
|
|
: Center(
|
|
child: Text(
|
|
c.qty.toString(),
|
|
style: textStyle,
|
|
),
|
|
)),
|
|
DataCell(
|
|
Text(c.weight.toStringAsFixed(2), style: textStyle),
|
|
),
|
|
],
|
|
);
|
|
}).toList();
|
|
|
|
var totalRow = DataRow(
|
|
onSelectChanged: (bool? selected) {},
|
|
cells: [
|
|
DataCell(Align(
|
|
alignment: Alignment.centerRight,
|
|
child: LocalText(
|
|
context,
|
|
"shipment.cargo.total",
|
|
color: Colors.black87,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
)),
|
|
DataCell(Text("")),
|
|
DataCell(
|
|
Padding(
|
|
padding: const EdgeInsets.only(right: 48.0),
|
|
child: Align(
|
|
alignment: Alignment.centerRight,
|
|
child: Text(total.toStringAsFixed(2)+" lb",
|
|
style: TextStyle(fontWeight: FontWeight.bold))),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
rows.add(totalRow);
|
|
return rows;
|
|
}
|
|
}
|