- override
Describes the part of the user interface represented by this widget.
The framework calls this method in a number of different situations:
- After calling
initState
. - After calling
didUpdateConfig
. - After receiving a call to
setState
. - After a dependency of this
State
object changes (e.g., anInheritedWidget
referenced by the previousbuild
changes). - After calling
deactivate
and then reinserting theState
object into the tree at another location.
The framework replaces the subtree below this widget with the widget
returned by this method, either by updating the existing subtree or by
removing the subtree and inflating a new subtree, depending on whether the
widget returned by this method can update the root of the existing
subtree, as determined by calling Widget.canUpdate
.
Typically implementations return a newly created constellation of widgets
that are configured with information from this widget's constructor, the
given BuildContext
, and the internal state of this State
object.
The given BuildContext
contains information about the location in the
tree at which this widget is being built. For example, the context
provides the set of inherited widgets for this location in the tree. The
BuildContext
argument is always the same as the context
property of
this State
object and will remain the same for the lifetime of this
object. The BuildContext
argument is provided redundantly here so that
this method matches the signature for a WidgetBuilder
.
Source
@override Widget build(BuildContext context) { // TODO(ianh): This whole build function doesn't handle RTL yet. ThemeData themeData = Theme.of(context); // HEADER final List<Widget> headerWidgets = <Widget>[]; double leftPadding = 24.0; if (_selectedRowCount == 0) { headerWidgets.add(new Expanded(child: config.header)); if (config.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. // TODO(ianh): Better magic. See https://github.com/flutter/flutter/issues/4460 leftPadding = 12.0; } } else if (_selectedRowCount == 1) { // TODO(ianh): Real l10n. headerWidgets.add(new Expanded(child: new Text('1 item selected'))); } else { headerWidgets.add(new Expanded(child: new Text('$_selectedRowCount items selected'))); } if (config.actions != null) { headerWidgets.addAll( config.actions.map/*<Widget>*/((Widget widget) { return new Padding( // 8.0 is the default padding of an icon button padding: const EdgeInsets.only(left: 24.0 - 8.0 * 2.0), child: widget ); }).toList() ); } // FOOTER final TextStyle footerTextStyle = themeData.textTheme.caption; final List<Widget> footerWidgets = <Widget>[]; if (config.onRowsPerPageChanged != null) { List<Widget> availableRowsPerPage = config.availableRowsPerPage .where((int value) => value <= _rowCount) .map/*<DropdownMenuItem<int>>*/((int value) { return new DropdownMenuItem<int>( value: value, child: new Text('$value') ); }) .toList(); footerWidgets.addAll(<Widget>[ new Text('Rows per page:'), new DropdownButtonHideUnderline( child: new DropdownButton<int>( items: availableRowsPerPage, value: config.rowsPerPage, onChanged: config.onRowsPerPageChanged, style: footerTextStyle, iconSize: 24.0 ) ), ]); } footerWidgets.addAll(<Widget>[ new Container(width: 32.0), new Text( '${_firstRowIndex + 1}\u2013${_firstRowIndex + config.rowsPerPage} ${ _rowCountApproximate ? "of about" : "of" } $_rowCount' ), new Container(width: 32.0), new IconButton( icon: new Icon(Icons.chevron_left), padding: EdgeInsets.zero, onPressed: _firstRowIndex <= 0 ? null : () { pageTo(math.max(_firstRowIndex - config.rowsPerPage, 0)); } ), new Container(width: 24.0), new IconButton( icon: new Icon(Icons.chevron_right), padding: EdgeInsets.zero, onPressed: (!_rowCountApproximate && (_firstRowIndex + config.rowsPerPage >= _rowCount)) ? null : () { pageTo(_firstRowIndex + config.rowsPerPage); } ), new Container(width: 14.0), ]); // CARD return new Card( child: new BlockBody( children: <Widget>[ new 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.google.com/components/data-tables.html#data-tables-tables-within-cards style: _selectedRowCount > 0 ? themeData.textTheme.subhead.copyWith(color: themeData.accentColor) : themeData.textTheme.title.copyWith(fontWeight: FontWeight.w400), child: new IconTheme.merge( context: context, data: const IconThemeData( opacity: 0.54 ), child: new ButtonTheme.bar( child: new Container( height: 64.0, padding: new EdgeInsets.fromLTRB(leftPadding, 0.0, 14.0, 0.0), // TODO(ianh): This decoration will prevent ink splashes from being visible. // Instead, we should have a widget that prints the decoration on the material. // See https://github.com/flutter/flutter/issues/3782 decoration: _selectedRowCount > 0 ? new BoxDecoration( backgroundColor: themeData.secondaryHeaderColor ) : null, child: new Row( mainAxisAlignment: MainAxisAlignment.end, children: headerWidgets ) ) ) ) ), new ScrollableViewport( scrollDirection: Axis.horizontal, child: new DataTable( key: _tableKey, columns: config.columns, sortColumnIndex: config.sortColumnIndex, sortAscending: config.sortAscending, onSelectAll: config.onSelectAll, rows: _getRows(_firstRowIndex, config.rowsPerPage) ) ), new DefaultTextStyle( style: footerTextStyle, child: new IconTheme.merge( context: context, data: const IconThemeData( opacity: 0.54 ), child: new Container( height: 56.0, child: new Row( mainAxisAlignment: MainAxisAlignment.end, children: footerWidgets ) ) ) ) ] ) ); }