createTableFooter method

Widget createTableFooter()

Implementation

Widget createTableFooter() {
  //Try to get the user custom footer
  final userFooterWidget = widget.customTableFooter?.call(
    widget.source,
    _firstRowIndex,
  );
  if (userFooterWidget == null) {
    //No footer present render the default one
    final themeData = Theme.of(context);
    final localizations = MaterialLocalizations.of(context);
    final currentLocale = Directionality.of(context);
    final footerTextStyle = themeData.textTheme.bodySmall;
    final footerWidgets = <Widget>[];
    if (widget.onRowsPerPageChanged != null) {
      final List<Widget> availableRowsPerPage =
          widget.availableRowsPerPage.map<DropdownMenuItem<int>>((int value) {
        return DropdownMenuItem<int>(
          value: value,
          key: ValueKey('opt_$value'),
          child: Text(
            '$value',
          ),
        );
      }).toList();
      footerWidgets.addAll(<Widget>[
        Container(
          width: 14.0,
        ), // to match trailing padding in case we overflow and end up scrolling
        Text(localizations.rowsPerPageTitle),
        ConstrainedBox(
          constraints: const BoxConstraints(
            minWidth: 64.0,
          ), // 40.0 for the text, 24.0 for the icon
          child: Align(
            alignment: AlignmentDirectional.centerEnd,
            child: DropdownButtonHideUnderline(
              key: const Key('rowsPerPageParent'),
              child: DropdownButton<int>(
                key: const Key('rowsPerPage'),
                items: availableRowsPerPage.cast<DropdownMenuItem<int>>(),
                value: widget.rowsPerPage,
                onTap: () {},
                onChanged: (newRowsPerPage) {
                  if (newRowsPerPage != null &&
                      newRowsPerPage != widget.rowsPerPage) {
                    setLoadNextPage(rowsPerPage: newRowsPerPage);
                    if (widget.onRowsPerPageChanged != null) {
                      widget.onRowsPerPageChanged?.call(newRowsPerPage);
                    }
                  }
                },
                style: footerTextStyle,
              ),
            ),
          ),
        ),
      ]);
    }
    footerWidgets.addAll(<Widget>[
      Container(width: 32.0),
      Text(
        buildDataAmountText(),
      ),
      Container(width: 32.0),
      if (widget.showFirstLastButtons && currentLocale == TextDirection.ltr)
        IconButton(
          icon: const Icon(Icons.skip_previous),
          padding: EdgeInsets.zero,
          onPressed: _firstRowIndex <= 0 ? null : _handleFirst,
        )
      else if (widget.showFirstLastButtons &&
          currentLocale == TextDirection.rtl)
        IconButton(
          icon: const Icon(Icons.skip_next),
          padding: EdgeInsets.zero,
          onPressed: _firstRowIndex <= 0 ? null : _handleFirst,
        ),
      IconButton(
        icon: const Icon(Icons.chevron_left),
        padding: EdgeInsets.zero,
        tooltip: localizations.previousPageTooltip,
        onPressed: _firstRowIndex <= 0 ? null : _handlePrevious,
      ),
      Container(width: 24.0),
      IconButton(
        icon: const Icon(Icons.chevron_right),
        padding: EdgeInsets.zero,
        tooltip: localizations.nextPageTooltip,
        onPressed: _isNextPageUnavailable() ? null : _handleNext,
      ),
      if (widget.showFirstLastButtons && currentLocale == TextDirection.ltr)
        IconButton(
          icon: const Icon(Icons.skip_next),
          padding: EdgeInsets.zero,
          onPressed: _isNextPageUnavailable() ? null : _handleLast,
        )
      else if (widget.showFirstLastButtons &&
          currentLocale == TextDirection.rtl)
        IconButton(
          icon: const Icon(Icons.skip_previous),
          padding: EdgeInsets.zero,
          onPressed: _firstRowIndex <= 0 ? null : _handleFirst,
        ),
      Container(width: 14.0),
    ]);
    return DefaultTextStyle(
      style: footerTextStyle!,
      child: IconTheme.merge(
        data: const IconThemeData(
          opacity: 0.54,
        ),
        child: SizedBox(
          height: 56.0,
          child: SingleChildScrollView(
            dragStartBehavior: widget.dragStartBehavior,
            scrollDirection: Axis.horizontal,
            child: Row(
              children: footerWidgets,
            ),
          ),
        ),
      ),
    );
  } else {
    return userFooterWidget;
  }
}