Exemple #1
0
        public override Widget build(BuildContext context)
        {
            D.assert(material_.debugCheckHasMaterialLocalizations(context));
            ThemeData             themeData     = Theme.of(context);
            MaterialLocalizations localizations = MaterialLocalizations.of(context);

            List <Widget> headerWidgets = new List <Widget>();

            float startPadding = 24.0f;

            if (_selectedRowCount == 0)
            {
                headerWidgets.Add(new Expanded(child: widget.header));
                if (widget.header is ButtonBar)
                {
                    startPadding = 12.0f;
                }
            }
            else
            {
                headerWidgets.Add(new Expanded(
                                      child: new Text(localizations.selectedRowCountTitle(_selectedRowCount))
                                      ));
            }

            if (widget.actions != null)
            {
                headerWidgets.AddRange(
                    LinqUtils <Widget> .SelectList(widget.actions, ((Widget action) => {
                    return(new Padding(
                               padding: EdgeInsetsDirectional.only(
                                   start: 24.0f - 8.0f * 2.0f),
                               child: action
                               ));
                }))
                    );
            }

            TextStyle     footerTextStyle = themeData.textTheme.caption;
            List <Widget> footerWidgets   = new List <Widget>();

            if (widget.onRowsPerPageChanged != null)
            {
                List <Widget> availableRowsPerPage = LinqUtils <Widget, int> .SelectList(
                    LinqUtils <int> .WhereList(widget.availableRowsPerPage, ((int value) => value <= _rowCount || value == widget.rowsPerPage)),
                    (int value) => {
                    return((Widget) new DropdownMenuItem <int>(
                               value: value,
                               child: new Text($"{value}")
                               ));
                });

                footerWidgets.AddRange(new List <Widget>()
                {
                    new Container(width: 14.0f), // to match trailing padding in case we overflow and end up scrolling
                    new Text(localizations.rowsPerPageTitle),
                    new ConstrainedBox(
                        constraints: new BoxConstraints(minWidth: 64.0f), // 40.0 for the text, 24.0 for the icon
                        child: new Align(
                            alignment: AlignmentDirectional.centerEnd,
                            child: new DropdownButtonHideUnderline(
                                child: new DropdownButton <int>(
                                    items: availableRowsPerPage.Cast <DropdownMenuItem <int> >().ToList(),
                                    value: widget.rowsPerPage,
                                    onChanged: widget.onRowsPerPageChanged,
                                    style: footerTextStyle,
                                    iconSize: 24.0f
                                    )
                                )
                            )
                        ),
                });
            }

            footerWidgets.AddRange(new List <Widget>()
            {
                new Container(width: 32.0f),
                new Text(
                    localizations.pageRowsInfoTitle(
                        _firstRowIndex + 1,
                        _firstRowIndex + widget.rowsPerPage,
                        _rowCount,
                        _rowCountApproximate
                        )
                    ),
                new Container(width: 32.0f),
                new IconButton(
                    icon: new Icon(Icons.chevron_left),
                    padding: EdgeInsets.zero,
                    tooltip:
                    localizations.previousPageTooltip,
                    onPressed: _firstRowIndex <= 0 ? (VoidCallback)null : _handlePrevious),
                new Container(width: 24.0f),
                new IconButton(
                    icon: new Icon(Icons.chevron_right),
                    padding: EdgeInsets.zero,
                    tooltip:
                    localizations.nextPageTooltip,
                    onPressed: (!_rowCountApproximate && (_firstRowIndex + widget.rowsPerPage >= _rowCount))
                        ? (VoidCallback)null
                        : _handleNext
                    ),

                new Container(width: 14.0f),
            });

            return(new LayoutBuilder(
                       builder: (BuildContext _context, BoxConstraints constraints) => {
                return new Card(
                    child: new Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: new List <Widget> {
                    new DefaultTextStyle(
                        style: _selectedRowCount > 0
                                        ? themeData.textTheme.subtitle1.copyWith(color: themeData.accentColor)
                                        : themeData.textTheme.headline6.copyWith(fontWeight: FontWeight.w400),
                        child: IconTheme.merge(
                            data: new IconThemeData(
                                opacity: 0.54f
                                ),
                            child: new Ink(
                                height: 64.0f,
                                color: _selectedRowCount > 0 ? themeData.secondaryHeaderColor : null,
                                child: new Padding(
                                    padding: EdgeInsetsDirectional.only(
                                        start: startPadding, end: 14.0f),
                                    child: new Row(
                                        mainAxisAlignment: MainAxisAlignment.end,
                                        children: headerWidgets
                                        )
                                    )
                                )
                            )
                        ),
                    new SingleChildScrollView(
                        scrollDirection: Axis.horizontal,
                        dragStartBehavior: widget.dragStartBehavior,
                        child: new ConstrainedBox(
                            constraints: new BoxConstraints(minWidth: constraints.minWidth),
                            child: new DataTable(
                                key: _tableKey,
                                columns: widget.columns,
                                sortColumnIndex: widget.sortColumnIndex,
                                sortAscending: widget.sortAscending,
                                onSelectAll: widget.onSelectAll,
                                dataRowHeight: widget.dataRowHeight,
                                headingRowHeight: widget.headingRowHeight,
                                horizontalMargin: widget.horizontalMargin,
                                columnSpacing: widget.columnSpacing,
                                rows: _getRows(_firstRowIndex, widget.rowsPerPage)
                                )
                            )
                        ),
                    new DefaultTextStyle(
                        style: footerTextStyle,
                        child: IconTheme.merge(
                            data: new IconThemeData(
                                opacity: 0.54f
                                ),
                            child:
                            new Container(
                                height: 56.0f,
                                child: new SingleChildScrollView(
                                    dragStartBehavior: widget.dragStartBehavior,
                                    scrollDirection: Axis.horizontal,
                                    reverse: true,
                                    child: new Row(
                                        children: footerWidgets
                                        )
                                    )
                                )
                            )
                        )
                }
                        )
                    );
            }
                       ));
        }