import 'package:fcs/domain/entities/carton.dart'; import 'package:fcs/domain/entities/package.dart'; import 'package:fcs/helpers/theme.dart'; import 'package:fcs/pages/widgets/local_text.dart'; import 'package:fcs/pages/widgets/local_title.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; typedef OnSelect = Function(Carton carton, bool checked); class InvoiceCartonTable extends StatelessWidget { final List cartons; final OnSelect onSelect; const InvoiceCartonTable({Key key, this.cartons, this.onSelect}) : super(key: key); @override Widget build(BuildContext context) { final tableTitle = Container( padding: EdgeInsets.only(right: 10.0, top: 20), child: Row( children: [ SizedBox( width: 50, ), SizedBox( width: 150, child: LocalText(context, 'invoice.box.number', color: Colors.grey), ), LocalText(context, 'invoice.shipment_weight', color: Colors.grey), ], ), ); final rows = cartons == null ? [Container()] : cartons.asMap().entries.map((p) { return Container( color: p.value.isChecked ? Colors.grey.withOpacity(0.2) : Colors.grey[50].withOpacity(0.2), child: Container( padding: EdgeInsets.only( left: 0.0, right: 10.0, top: 3.0, bottom: 3.0), decoration: BoxDecoration( border: Border( bottom: BorderSide( color: p.key == cartons.length - 1 ? Colors.white : Colors.grey[350], width: 1), ), ), child: Row( children: [ onSelect == null ? p.value.isChecked ? SizedBox( child: Icon(Icons.check, color: primaryColor), width: 30) : SizedBox(width: 30) : Checkbox( value: p.value.isChecked, activeColor: primaryColor, onChanged: (bool check) { if (onSelect != null) onSelect(p.value, check); }), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( p.value.cartonNumber, style: textStyle, ), Text( p.value.shipmentNumber ?? "", style: textStyle, ), ], )), Flexible( child: new Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ new Text( "${p.value?.length ?? ""} x ${p.value?.width ?? ""} x ${p.value?.height ?? ""}", style: textStyle, ), ], ), ) ], ), ), ); }).toList(); return Column( children: [ LocalTitle(textKey: "invoice.box_info"), tableTitle, Divider( color: Colors.grey[400], ), Column( children: rows, ), ], ); } }