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 { final List? cargoTypes; const CargoTable({ Key? key, this.cargoTypes, }) : super(key: key); @override _CargoTableState createState() => _CargoTableState(); } class _CargoTableState extends State { @override Widget build(BuildContext context) { return SingleChildScrollView( scrollDirection: Axis.horizontal, child: MyDataTable( headingRowHeight: 40, columnSpacing: 50, columns: [ MyDataColumn( label: LocalText( context, "cargo.type", color: Colors.grey, ), ), MyDataColumn( label: LocalText( context, "cargo.qty", color: Colors.grey, ), ), MyDataColumn( label: LocalText( context, "cargo.weight", color: Colors.grey, ), ), ], rows: getCargoRows(context), ), ); } List getCargoRows(BuildContext context) { if (widget.cargoTypes == null) { return []; } double total = 0; var rows = widget.cargoTypes!.map((c) { total += c.weight; return MyDataRow( onSelectChanged: (bool selected) async {}, cells: [ MyDataCell(new Text( c.name ?? "", style: textStyle, )), MyDataCell(c.qty == null || c.qty == 0 ? Center( child: Text( "-", style: textStyle, ), ) : Center( child: Text( c.qty.toString(), style: textStyle, ), )), MyDataCell( Text(c.weight == null ? "0" : c.weight.toStringAsFixed(2), style: textStyle), ), ], ); }).toList(); var totalRow = MyDataRow( onSelectChanged: (bool selected) {}, cells: [ MyDataCell(Align( alignment: Alignment.centerRight, child: LocalText( context, "shipment.cargo.total", color: Colors.black87, fontWeight: FontWeight.bold, ), )), MyDataCell(Text("")), MyDataCell( 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; } }