Table.fromTextArray constructor
Table.fromTextArray({
- List<
String> ? headers, - required List<
List< data,String> > - bool border = true,
- TableBorder? tableBorder,
- List<
double> ? columnWidths, - Map<
int, TableColumnWidth> ? columnWidthSpec, - TextStyle? headerStyle,
- TextStyle? cellStyle,
- TextStyle? oddCellStyle,
- AlignmentGeometry headerAlignment = Alignment.center,
- AlignmentGeometry cellAlignment = AlignmentDirectional.topStart,
- Map<
int, AlignmentGeometry> ? cellAlignments, - Map<
int, AlignmentGeometry> ? headerAlignments, - EdgeInsets cellPadding = const EdgeInsets.all(5),
- EdgeInsets? headerPadding,
- double cellHeight = 0,
- double? headerHeight,
- String? headerDecoration,
- String? headerCellDecoration,
- String? rowDecoration,
- String? oddRowDecoration,
- TableCellVerticalAlignment verticalAlignment = TableCellVerticalAlignment.full,
fromTextArray API — mirrors package:pdf TableHelper.fromTextArray.
Implementation
factory Table.fromTextArray({
List<String>? headers,
required List<List<String>> data,
bool border = true,
TableBorder? tableBorder,
List<double>? columnWidths,
Map<int, TableColumnWidth>? columnWidthSpec,
TextStyle? headerStyle,
TextStyle? cellStyle,
TextStyle? oddCellStyle,
AlignmentGeometry headerAlignment = Alignment.center,
AlignmentGeometry cellAlignment = AlignmentDirectional.topStart,
Map<int, AlignmentGeometry>? cellAlignments,
Map<int, AlignmentGeometry>? headerAlignments,
EdgeInsets cellPadding = const EdgeInsets.all(5),
EdgeInsets? headerPadding,
double cellHeight = 0,
double? headerHeight,
String? headerDecoration,
String? headerCellDecoration,
String? rowDecoration,
String? oddRowDecoration,
TableCellVerticalAlignment verticalAlignment =
TableCellVerticalAlignment.full,
}) {
headerPadding ??= cellPadding;
headerHeight ??= cellHeight;
// Match package:pdf: only zebra when the caller asks for it.
final String? oddBand = oddRowDecoration;
final String? evenBand = rowDecoration;
oddCellStyle ??= cellStyle;
final Map<int, AlignmentGeometry> cellAlign =
cellAlignments ?? const <int, AlignmentGeometry>{};
final Map<int, AlignmentGeometry> headerAlign =
headerAlignments ?? cellAlign;
final List<TableRow> rows = <TableRow>[];
if (headers != null) {
rows.add(
TableRow(
repeat: true,
decoration: BoxDecoration(
color: headerDecoration ?? '1A237E',
),
verticalAlignment: verticalAlignment,
children: <Widget>[
for (int i = 0; i < headers.length; i++)
Container(
color: headerCellDecoration,
padding: headerPadding,
alignment: headerAlign[i] ?? headerAlignment,
constraints: headerHeight > 0
? BoxConstraints(minHeight: headerHeight)
: null,
child: Text(
headers[i],
style:
headerStyle ??
const TextStyle(
color: 'FFFFFF',
fontWeight: FontWeight.bold,
fontSize: 10,
),
),
),
],
),
);
}
for (int r = 0; r < data.length; r++) {
final bool odd = r.isOdd;
final String? band = odd ? oddBand : evenBand;
rows.add(
TableRow(
decoration: band == null ? null : BoxDecoration(color: band),
verticalAlignment: verticalAlignment,
children: <Widget>[
for (int c = 0; c < data[r].length; c++)
Container(
padding: cellPadding,
alignment: cellAlign[c] ?? cellAlignment,
constraints: cellHeight > 0
? BoxConstraints(minHeight: cellHeight)
: null,
child: Text(
data[r][c],
style: (odd ? oddCellStyle : cellStyle) ??
const TextStyle(fontSize: 10),
),
),
],
),
);
}
return Table(
children: rows,
border: border,
tableBorder: tableBorder,
columnWidths: columnWidths,
columnWidthSpec: columnWidthSpec,
borderColor: '90A4AE',
defaultVerticalAlignment: verticalAlignment,
);
}