buildTableWhenReady method
Original build method from the Flutter PageinatedDataTable
Implementation
Widget buildTableWhenReady(
BoxConstraints constraints, {
bool loading = false,
}) {
assert(debugCheckHasMaterialLocalizations(context));
final themeData = Theme.of(context);
final localizations = MaterialLocalizations.of(context);
// HEADER
final headerWidgets = <Widget>[];
var startPadding = 24.0;
if (_selectedRowCount == 0 && widget.header != null) {
headerWidgets.add(Expanded(child: widget.header!));
if (widget.header is ButtonBar) {
// We adjust the padding when a button bar is present, because the
// ButtonBar introduces 2 pixels of outside padding, plus 2 pixels
// around each button on each side, and the button itself will have 8
// pixels internally on each side, yet we want the left edge of the
// inside of the button to line up with the 24.0 left inset.
startPadding = 12.0;
}
} else if (widget.header != null) {
headerWidgets.add(
Expanded(
child: Text(localizations.selectedRowCountTitle(_selectedRowCount)),
),
);
}
if (widget.actions != null) {
headerWidgets.addAll(
widget.actions!.map<Widget>((Widget action) {
return Padding(
// 8.0 is the default padding of an icon button
padding: const EdgeInsetsDirectional.only(start: 24.0 - 8.0 * 2.0),
child: action,
);
}).toList(),
);
}
return Stack(
children: [
if (loading)
const Padding(
padding: EdgeInsets.all(20),
child: Center(child: CircularProgressIndicator()),
)
else
Scrollbar(
controller: scroller,
thumbVisibility: widget.showHorizontalScrollbarAlways,
child: Card(
semanticContainer: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
if (headerWidgets.isNotEmpty)
Semantics(
container: true,
child: DefaultTextStyle(
// These typographic styles aren't quite the regular ones. We pick the closest ones from the regular
// list and then tweak them appropriately.
// See https://material.io/design/components/data-tables.html#tables-within-cards
style: _selectedRowCount > 0
? themeData.textTheme.titleMedium!.copyWith(
color: themeData.colorScheme.secondary,
)
: themeData.textTheme.titleLarge!
.copyWith(fontWeight: FontWeight.w400),
child: IconTheme.merge(
data: const IconThemeData(
opacity: 0.54,
),
child: Ink(
height: 64.0,
color: _selectedRowCount > 0
? themeData.secondaryHeaderColor
: null,
child: Padding(
padding: EdgeInsetsDirectional.only(
start: startPadding,
end: 14.0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: headerWidgets,
),
),
),
),
),
),
SingleChildScrollView(
controller: scroller,
scrollDirection: Axis.horizontal,
dragStartBehavior: widget.dragStartBehavior,
child: ConstrainedBox(
constraints:
BoxConstraints(minWidth: constraints.maxWidth),
child: DataTable(
key: _tableKey,
columns: widget.columns,
sortColumnIndex: widget.sortColumnIndex,
sortAscending: widget.sortAscending,
onSelectAll: widget.onSelectAll,
// Make sure no decoration is set on the DataTable
// from the theme, as its already wrapped in a Card.
decoration: const BoxDecoration(),
dataRowMinHeight: widget.dataRowHeight,
dataRowMaxHeight: widget.dataRowHeight,
headingRowHeight: widget.headingRowHeight,
horizontalMargin: widget.horizontalMargin,
columnSpacing: widget.columnSpacing,
showCheckboxColumn: widget.showCheckboxColumn,
showBottomBorder: true,
rows: _getRows(_firstRowIndex, widget.rowsPerPage),
),
),
),
if (!loading)
Align(
alignment: widget.defaultFootAlignment,
child: createTableFooter(),
),
],
),
),
),
],
);
}