data_table.dart 45.1 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:math' as math;

7
import 'package:flutter/foundation.dart';
8 9 10 11
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

import 'checkbox.dart';
12
import 'constants.dart';
13
import 'data_table_theme.dart';
14
import 'debug.dart';
15
import 'divider.dart';
16
import 'dropdown.dart';
17 18 19
import 'icons.dart';
import 'ink_well.dart';
import 'material.dart';
20
import 'material_state.dart';
21 22 23
import 'theme.dart';
import 'tooltip.dart';

24
/// Signature for [DataColumn.onSort] callback.
25
typedef DataColumnSortCallback = void Function(int columnIndex, bool ascending);
26 27 28 29 30

/// Column configuration for a [DataTable].
///
/// One column configuration must be provided for each column to
/// display in the table. The list of [DataColumn] objects is passed
31
/// as the `columns` argument to the [DataTable.new] constructor.
32
@immutable
33 34 35 36 37
class DataColumn {
  /// Creates the configuration for a column of a [DataTable].
  ///
  /// The [label] argument must not be null.
  const DataColumn({
38
    required this.label,
39
    this.tooltip,
40
    this.numeric = false,
41
    this.onSort,
42
  }) : assert(label != null);
43 44 45 46 47 48 49

  /// The column heading.
  ///
  /// Typically, this will be a [Text] widget. It could also be an
  /// [Icon] (typically using size 18), or a [Row] with an icon and
  /// some text.
  ///
50 51 52 53 54 55 56 57
  /// The [label] is placed within a [Row] along with the
  /// sort indicator (if applicable). By default, [label] only occupy minimal
  /// space. It is recommended to place the label content in an [Expanded] or
  /// [Flexible] as [label] to control how the content flexes. Otherwise,
  /// an exception will occur when the available space is insufficient.
  ///
  /// By default, [DefaultTextStyle.softWrap] of this subtree will be set to false.
  /// Use [DefaultTextStyle.merge] to override it if needed.
58
  ///
59 60 61 62 63 64 65 66
  /// The label should not include the sort indicator.
  final Widget label;

  /// The column heading's tooltip.
  ///
  /// This is a longer description of the column heading, for cases
  /// where the heading might have been abbreviated to keep the column
  /// width to a reasonable size.
67
  final String? tooltip;
68 69 70 71 72 73 74

  /// Whether this column represents numeric data or not.
  ///
  /// The contents of cells of columns containing numeric data are
  /// right-aligned.
  final bool numeric;

75
  /// Called when the user asks to sort the table using this column.
76 77 78 79
  ///
  /// If null, the column will not be considered sortable.
  ///
  /// See [DataTable.sortColumnIndex] and [DataTable.sortAscending].
80
  final DataColumnSortCallback? onSort;
81 82 83 84 85 86 87 88

  bool get _debugInteractive => onSort != null;
}

/// Row configuration and cell data for a [DataTable].
///
/// One row configuration must be provided for each row to
/// display in the table. The list of [DataRow] objects is passed
89
/// as the `rows` argument to the [DataTable.new] constructor.
90 91 92
///
/// The data for this row of the table is provided in the [cells]
/// property of the [DataRow] object.
93
@immutable
94 95 96 97 98 99
class DataRow {
  /// Creates the configuration for a row of a [DataTable].
  ///
  /// The [cells] argument must not be null.
  const DataRow({
    this.key,
100
    this.selected = false,
101
    this.onSelectChanged,
102
    this.onLongPress,
103
    this.color,
104
    required this.cells,
105
  }) : assert(cells != null);
106

107 108 109 110 111
  /// Creates the configuration for a row of a [DataTable], deriving
  /// the key from a row index.
  ///
  /// The [cells] argument must not be null.
  DataRow.byIndex({
112
    int? index,
113
    this.selected = false,
114
    this.onSelectChanged,
115
    this.onLongPress,
116
    this.color,
117
    required this.cells,
118
  }) : assert(cells != null),
119
       key = ValueKey<int?>(index);
120

121 122 123 124 125 126
  /// A [Key] that uniquely identifies this row. This is used to
  /// ensure that if a row is added or removed, any stateful widgets
  /// related to this row (e.g. an in-progress checkbox animation)
  /// remain on the right row visually.
  ///
  /// If the table never changes once created, no key is necessary.
127
  final LocalKey? key;
128

129
  /// Called when the user selects or unselects a selectable row.
130 131 132 133 134 135 136 137 138 139 140 141
  ///
  /// If this is not null, then the row is selectable. The current
  /// selection state of the row is given by [selected].
  ///
  /// If any row is selectable, then the table's heading row will have
  /// a checkbox that can be checked to select all selectable rows
  /// (and which is checked if all the rows are selected), and each
  /// subsequent row will have a checkbox to toggle just that row.
  ///
  /// A row whose [onSelectChanged] callback is null is ignored for
  /// the purposes of determining the state of the "all" checkbox,
  /// and its checkbox is disabled.
142 143 144 145
  ///
  /// If a [DataCell] in the row has its [DataCell.onTap] callback defined,
  /// that callback behavior overrides the gesture behavior of the row for
  /// that particular cell.
146
  final ValueChanged<bool?>? onSelectChanged;
147

148 149 150 151 152 153 154 155
  /// Called if the row is long-pressed.
  ///
  /// If a [DataCell] in the row has its [DataCell.onTap], [DataCell.onDoubleTap],
  /// [DataCell.onLongPress], [DataCell.onTapCancel] or [DataCell.onTapDown] callback defined,
  /// that callback behavior overrides the gesture behavior of the row for
  /// that particular cell.
  final GestureLongPressCallback? onLongPress;

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
  /// Whether the row is selected.
  ///
  /// If [onSelectChanged] is non-null for any row in the table, then
  /// a checkbox is shown at the start of each row. If the row is
  /// selected (true), the checkbox will be checked and the row will
  /// be highlighted.
  ///
  /// Otherwise, the checkbox, if present, will not be checked.
  final bool selected;

  /// The data for this row.
  ///
  /// There must be exactly as many cells as there are columns in the
  /// table.
  final List<DataCell> cells;

172 173 174 175 176 177 178 179 180 181 182 183 184
  /// The color for the row.
  ///
  /// By default, the color is transparent unless selected. Selected rows has
  /// a grey translucent color.
  ///
  /// The effective color can depend on the [MaterialState] state, if the
  /// row is selected, pressed, hovered, focused, disabled or enabled. The
  /// color is painted as an overlay to the row. To make sure that the row's
  /// [InkWell] is visible (when pressed, hovered and focused), it is
  /// recommended to use a translucent color.
  ///
  /// ```dart
  /// DataRow(
185
  ///   color: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
186 187 188
  ///     if (states.contains(MaterialState.selected))
  ///       return Theme.of(context).colorScheme.primary.withOpacity(0.08);
  ///     return null;  // Use the default value.
189 190
  ///   }),
  /// )
191 192 193 194 195 196 197
  /// ```
  ///
  /// See also:
  ///
  ///  * The Material Design specification for overlay colors and how they
  ///    match a component's state:
  ///    <https://material.io/design/interaction/states.html#anatomy>.
198
  final MaterialStateProperty<Color?>? color;
199

200 201 202 203 204 205
  bool get _debugInteractive => onSelectChanged != null || cells.any((DataCell cell) => cell._debugInteractive);
}

/// The data for a cell of a [DataTable].
///
/// One list of [DataCell] objects must be provided for each [DataRow]
206
/// in the [DataTable], in the new [DataRow] constructor's `cells`
207
/// argument.
208
@immutable
209 210 211 212
class DataCell {
  /// Creates an object to hold the data for a cell in a [DataTable].
  ///
  /// The first argument is the widget to show for the cell, typically
213
  /// a [Text] or [DropdownButton] widget; this becomes the [child]
214 215 216 217 218
  /// property and must not be null.
  ///
  /// If the cell has no data, then a [Text] widget with placeholder
  /// text should be provided instead, and then the [placeholder]
  /// argument should be set to true.
219 220
  const DataCell(
    this.child, {
221 222
    this.placeholder = false,
    this.showEditIcon = false,
223
    this.onTap,
224 225 226 227
    this.onLongPress,
    this.onTapDown,
    this.onDoubleTap,
    this.onTapCancel,
228
  }) : assert(child != null);
229

230
  /// A cell that has no content and has zero width and height.
231
  static const DataCell empty = DataCell(SizedBox(width: 0.0, height: 0.0));
232

233 234
  /// The data for the row.
  ///
235
  /// Typically a [Text] widget or a [DropdownButton] widget.
236 237 238 239
  ///
  /// If the cell has no data, then a [Text] widget with placeholder
  /// text should be provided instead, and [placeholder] should be set
  /// to true.
240
  ///
241
  /// {@macro flutter.widgets.ProxyWidget.child}
242
  final Widget child;
243

244
  /// Whether the [child] is actually a placeholder.
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
  ///
  /// If this is true, the default text style for the cell is changed
  /// to be appropriate for placeholder text.
  final bool placeholder;

  /// Whether to show an edit icon at the end of the cell.
  ///
  /// This does not make the cell actually editable; the caller must
  /// implement editing behavior if desired (initiated from the
  /// [onTap] callback).
  ///
  /// If this is set, [onTap] should also be set, otherwise tapping
  /// the icon will have no effect.
  final bool showEditIcon;

260
  /// Called if the cell is tapped.
261
  ///
262
  /// If non-null, tapping the cell will call this callback. If
263 264
  /// null (including [onDoubleTap], [onLongPress], [onTapCancel] and [onTapDown]),
  /// tapping the cell will attempt to select the row (if
265
  /// [DataRow.onSelectChanged] is provided).
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
  final GestureTapCallback? onTap;

  /// Called when the cell is double tapped.
  ///
  /// If non-null, tapping the cell will call this callback. If
  /// null (including [onTap], [onLongPress], [onTapCancel] and [onTapDown]),
  /// tapping the cell will attempt to select the row (if
  /// [DataRow.onSelectChanged] is provided).
  final GestureTapCallback? onDoubleTap;

  /// Called if the cell is long-pressed.
  ///
  /// If non-null, tapping the cell will invoke this callback. If
  /// null (including [onDoubleTap], [onTap], [onTapCancel] and [onTapDown]),
  /// tapping the cell will attempt to select the row (if
  /// [DataRow.onSelectChanged] is provided).
  final GestureLongPressCallback? onLongPress;

  /// Called if the cell is tapped down.
  ///
  /// If non-null, tapping the cell will call this callback. If
  /// null (including [onTap] [onDoubleTap], [onLongPress] and [onTapCancel]),
  /// tapping the cell will attempt to select the row (if
  /// [DataRow.onSelectChanged] is provided).
  final GestureTapDownCallback? onTapDown;

  /// Called if the user cancels a tap was started on cell.
293
  ///
294 295 296 297 298
  /// If non-null, cancelling the tap gesture will invoke this callback.
  /// If null (including [onTap], [onDoubleTap] and [onLongPress]),
  /// tapping the cell will attempt to select the
  /// row (if [DataRow.onSelectChanged] is provided).
  final GestureTapCancelCallback? onTapCancel;
299

300 301 302 303 304
  bool get _debugInteractive => onTap != null ||
      onDoubleTap != null ||
      onLongPress != null ||
      onTapDown != null ||
      onTapCancel != null;
305 306
}

307
/// A Material Design data table.
308
///
309 310
/// {@youtube 560 315 https://www.youtube.com/watch?v=ktTajqbhIcY}
///
311 312 313 314 315
/// Displaying data in a table is expensive, because to lay out the
/// table all the data must be measured twice, once to negotiate the
/// dimensions to use for each column, and once to actually lay out
/// the table given the results of the negotiation.
///
316 317 318 319 320
/// For this reason, if you have a lot of data (say, more than a dozen
/// rows with a dozen columns, though the precise limits depend on the
/// target device), it is suggested that you use a
/// [PaginatedDataTable] which automatically splits the data into
/// multiple pages.
321
///
322
/// {@tool dartpad}
323 324 325 326 327 328 329
/// This sample shows how to display a [DataTable] with three columns: name, age, and
/// role. The columns are defined by three [DataColumn] objects. The table
/// contains three rows of data for three example users, the data for which
/// is defined by three [DataRow] objects.
///
/// ![](https://flutter.github.io/assets-for-api-docs/assets/material/data_table.png)
///
330
/// ** See code in examples/api/lib/material/data_table/data_table.0.dart **
331
/// {@end-tool}
332
///
333
///
334
/// {@tool dartpad}
335 336 337
/// This sample shows how to display a [DataTable] with alternate colors per
/// row, and a custom color for when the row is selected.
///
338
/// ** See code in examples/api/lib/material/data_table/data_table.1.dart **
339 340
/// {@end-tool}
///
341 342 343 344 345
/// [DataTable] can be sorted on the basis of any column in [columns] in
/// ascending or descending order. If [sortColumnIndex] is non-null, then the
/// table will be sorted by the values in the specified column. The boolean
/// [sortAscending] flag controls the sort order.
///
346 347
/// See also:
///
Adam Barth's avatar
Adam Barth committed
348 349 350 351 352
///  * [DataColumn], which describes a column in the data table.
///  * [DataRow], which contains the data for a row in the data table.
///  * [DataCell], which contains the data for a single cell in the data table.
///  * [PaginatedDataTable], which shows part of the data in a data table and
///    provides controls for paging through the remainder of the data.
353
///  * <https://material.io/design/components/data-tables.html>
354 355 356 357 358 359
class DataTable extends StatelessWidget {
  /// Creates a widget describing a data table.
  ///
  /// The [columns] argument must be a list of as many [DataColumn]
  /// objects as the table is to have columns, ignoring the leading
  /// checkbox column if any. The [columns] argument must have a
360
  /// length greater than zero and must not be null.
361
  ///
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
  /// The [rows] argument must be a list of as many [DataRow] objects
  /// as the table is to have rows, ignoring the leading heading row
  /// that contains the column headings (derived from the [columns]
  /// argument). There may be zero rows, but the rows argument must
  /// not be null.
  ///
  /// Each [DataRow] object in [rows] must have as many [DataCell]
  /// objects in the [DataRow.cells] list as the table has columns.
  ///
  /// If the table is sorted, the column that provides the current
  /// primary key should be specified by index in [sortColumnIndex], 0
  /// meaning the first column in [columns], 1 being the next one, and
  /// so forth.
  ///
  /// The actual sort order can be specified using [sortAscending]; if
  /// the sort order is ascending, this should be true (the default),
  /// otherwise it should be false.
  DataTable({
380
    super.key,
381
    required this.columns,
382
    this.sortColumnIndex,
383
    this.sortAscending = true,
384
    this.onSelectAll,
385
    this.decoration,
386 387 388 389 390 391 392 393
    this.dataRowColor,
    this.dataRowHeight,
    this.dataTextStyle,
    this.headingRowColor,
    this.headingRowHeight,
    this.headingTextStyle,
    this.horizontalMargin,
    this.columnSpacing,
394
    this.showCheckboxColumn = true,
395 396
    this.showBottomBorder = false,
    this.dividerThickness,
397
    required this.rows,
398
    this.checkboxHorizontalMargin,
399
    this.border,
400 401 402 403
  }) : assert(columns != null),
       assert(columns.isNotEmpty),
       assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
       assert(sortAscending != null),
404
       assert(showCheckboxColumn != null),
405 406
       assert(rows != null),
       assert(!rows.any((DataRow row) => row.cells.length != columns.length)),
407
       assert(dividerThickness == null || dividerThickness >= 0),
408
       _onlyTextColumn = _initOnlyTextColumn(columns);
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423

  /// The configuration and labels for the columns in the table.
  final List<DataColumn> columns;

  /// The current primary sort key's column.
  ///
  /// If non-null, indicates that the indicated column is the column
  /// by which the data is sorted. The number must correspond to the
  /// index of the relevant column in [columns].
  ///
  /// Setting this will cause the relevant column to have a sort
  /// indicator displayed.
  ///
  /// When this is null, it implies that the table's sort order does
  /// not correspond to any of the columns.
424
  final int? sortColumnIndex;
425 426 427 428 429 430 431 432 433 434 435 436 437

  /// Whether the column mentioned in [sortColumnIndex], if any, is sorted
  /// in ascending order.
  ///
  /// If true, the order is ascending (meaning the rows with the
  /// smallest values for the current sort column are first in the
  /// table).
  ///
  /// If false, the order is descending (meaning the rows with the
  /// smallest values for the current sort column are last in the
  /// table).
  final bool sortAscending;

438 439 440 441 442 443 444 445 446
  /// Invoked when the user selects or unselects every row, using the
  /// checkbox in the heading row.
  ///
  /// If this is null, then the [DataRow.onSelectChanged] callback of
  /// every row in the table is invoked appropriately instead.
  ///
  /// To control whether a particular row is selectable or not, see
  /// [DataRow.onSelectChanged]. This callback is only relevant if any
  /// row is selectable.
447
  final ValueSetter<bool?>? onSelectAll;
448

449 450 451 452 453 454 455 456
  /// {@template flutter.material.dataTable.decoration}
  /// The background and border decoration for the table.
  /// {@endtemplate}
  ///
  /// If null, [DataTableThemeData.decoration] is used. By default there is no
  /// decoration.
  final Decoration? decoration;

457 458 459 460 461 462 463 464 465 466 467
  /// {@template flutter.material.dataTable.dataRowColor}
  /// The background color for the data rows.
  ///
  /// The effective background color can be made to depend on the
  /// [MaterialState] state, i.e. if the row is selected, pressed, hovered,
  /// focused, disabled or enabled. The color is painted as an overlay to the
  /// row. To make sure that the row's [InkWell] is visible (when pressed,
  /// hovered and focused), it is recommended to use a translucent background
  /// color.
  /// {@endtemplate}
  ///
468 469 470 471
  /// If null, [DataTableThemeData.dataRowColor] is used. By default, the
  /// background color is transparent unless selected. Selected rows have a grey
  /// translucent color. To set a different color for individual rows, see
  /// [DataRow.color].
472
  ///
473
  /// {@template flutter.material.DataTable.dataRowColor}
474 475
  /// ```dart
  /// DataTable(
476
  ///   dataRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
477 478 479 480 481 482 483 484 485 486 487 488 489
  ///     if (states.contains(MaterialState.selected))
  ///       return Theme.of(context).colorScheme.primary.withOpacity(0.08);
  ///     return null;  // Use the default value.
  ///   }),
  /// )
  /// ```
  ///
  /// See also:
  ///
  ///  * The Material Design specification for overlay colors and how they
  ///    match a component's state:
  ///    <https://material.io/design/interaction/states.html#anatomy>.
  /// {@endtemplate}
490
  final MaterialStateProperty<Color?>? dataRowColor;
491 492

  /// {@template flutter.material.dataTable.dataRowHeight}
493
  /// The height of each row (excluding the row that contains column headings).
494
  /// {@endtemplate}
495
  ///
496 497 498
  /// If null, [DataTableThemeData.dataRowHeight] is used. This value defaults
  /// to [kMinInteractiveDimension] to adhere to the Material Design
  /// specifications.
499
  final double? dataRowHeight;
500

501 502 503 504
  /// {@template flutter.material.dataTable.dataTextStyle}
  /// The text style for data rows.
  /// {@endtemplate}
  ///
505 506
  /// If null, [DataTableThemeData.dataTextStyle] is used. By default, the text
  /// style is [TextTheme.bodyText2].
507
  final TextStyle? dataTextStyle;
508 509 510 511 512 513 514 515 516

  /// {@template flutter.material.dataTable.headingRowColor}
  /// The background color for the heading row.
  ///
  /// The effective background color can be made to depend on the
  /// [MaterialState] state, i.e. if the row is pressed, hovered, focused when
  /// sorted. The color is painted as an overlay to the row. To make sure that
  /// the row's [InkWell] is visible (when pressed, hovered and focused), it is
  /// recommended to use a translucent color.
517
  /// {@endtemplate}
518
  ///
519 520
  /// If null, [DataTableThemeData.headingRowColor] is used.
  ///
521
  /// {@template flutter.material.DataTable.headingRowColor}
522 523
  /// ```dart
  /// DataTable(
524
  ///   headingRowColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
525 526 527 528 529 530 531 532 533 534 535 536 537
  ///     if (states.contains(MaterialState.hovered))
  ///       return Theme.of(context).colorScheme.primary.withOpacity(0.08);
  ///     return null;  // Use the default value.
  ///   }),
  /// )
  /// ```
  ///
  /// See also:
  ///
  ///  * The Material Design specification for overlay colors and how they
  ///    match a component's state:
  ///    <https://material.io/design/interaction/states.html#anatomy>.
  /// {@endtemplate}
538
  final MaterialStateProperty<Color?>? headingRowColor;
539 540

  /// {@template flutter.material.dataTable.headingRowHeight}
541
  /// The height of the heading row.
542
  /// {@endtemplate}
543
  ///
544 545
  /// If null, [DataTableThemeData.headingRowHeight] is used. This value
  /// defaults to 56.0 to adhere to the Material Design specifications.
546
  final double? headingRowHeight;
547

548 549 550 551
  /// {@template flutter.material.dataTable.headingTextStyle}
  /// The text style for the heading row.
  /// {@endtemplate}
  ///
552 553
  /// If null, [DataTableThemeData.headingTextStyle] is used. By default, the
  /// text style is [TextTheme.subtitle2].
554
  final TextStyle? headingTextStyle;
555 556

  /// {@template flutter.material.dataTable.horizontalMargin}
557 558 559 560 561
  /// The horizontal margin between the edges of the table and the content
  /// in the first and last cells of each row.
  ///
  /// When a checkbox is displayed, it is also the margin between the checkbox
  /// the content in the first data column.
562
  /// {@endtemplate}
563
  ///
564 565
  /// If null, [DataTableThemeData.horizontalMargin] is used. This value
  /// defaults to 24.0 to adhere to the Material Design specifications.
566 567 568 569
  ///
  /// If [checkboxHorizontalMargin] is null, then [horizontalMargin] is also the
  /// margin between the edge of the table and the checkbox, as well as the
  /// margin between the checkbox and the content in the first data column.
570
  final double? horizontalMargin;
571

572
  /// {@template flutter.material.dataTable.columnSpacing}
573
  /// The horizontal margin between the contents of each data column.
574
  /// {@endtemplate}
575
  ///
576 577
  /// If null, [DataTableThemeData.columnSpacing] is used. This value defaults
  /// to 56.0 to adhere to the Material Design specifications.
578
  final double? columnSpacing;
579

580 581 582
  /// {@template flutter.material.dataTable.showCheckboxColumn}
  /// Whether the widget should display checkboxes for selectable rows.
  ///
583
  /// If true, a [Checkbox] will be placed at the beginning of each row that is
584 585 586
  /// selectable. However, if [DataRow.onSelectChanged] is not set for any row,
  /// checkboxes will not be placed, even if this value is true.
  ///
587
  /// If false, all rows will not display a [Checkbox].
588 589 590
  /// {@endtemplate}
  final bool showCheckboxColumn;

591
  /// The data to show in each row (excluding the row that contains
592 593 594
  /// the column headings).
  ///
  /// Must be non-null, but may be empty.
595 596
  final List<DataRow> rows;

597 598 599 600 601
  /// {@template flutter.material.dataTable.dividerThickness}
  /// The width of the divider that appears between [TableRow]s.
  ///
  /// Must be greater than or equal to zero.
  /// {@endtemplate}
602 603 604
  ///
  /// If null, [DataTableThemeData.dividerThickness] is used. This value
  /// defaults to 1.0.
605
  final double? dividerThickness;
606 607 608 609

  /// Whether a border at the bottom of the table is displayed.
  ///
  /// By default, a border is not shown at the bottom to allow for a border
610
  /// around the table defined by [decoration].
611 612
  final bool showBottomBorder;

613 614 615 616 617 618 619 620 621 622
  /// {@template flutter.material.dataTable.checkboxHorizontalMargin}
  /// Horizontal margin around the checkbox, if it is displayed.
  /// {@endtemplate}
  ///
  /// If null, [DataTableThemeData.checkboxHorizontalMargin] is used. If that is
  /// also null, then [horizontalMargin] is used as the margin between the edge
  /// of the table and the checkbox, as well as the margin between the checkbox
  /// and the content in the first data column. This value defaults to 24.0.
  final double? checkboxHorizontalMargin;

623 624 625
  /// The style to use when painting the boundary and interior divisions of the table.
  final TableBorder? border;

626 627
  // Set by the constructor to the index of the only Column that is
  // non-numeric, if there is exactly one, otherwise null.
628 629 630
  final int? _onlyTextColumn;
  static int? _initOnlyTextColumn(List<DataColumn> columns) {
    int? result;
631
    for (int index = 0; index < columns.length; index += 1) {
632
      final DataColumn column = columns[index];
633
      if (!column.numeric) {
634
        if (result != null) {
635
          return null;
636
        }
637 638 639 640 641 642 643 644 645 646 647
        result = index;
      }
    }
    return result;
  }

  bool get _debugInteractive {
    return columns.any((DataColumn column) => column._debugInteractive)
        || rows.any((DataRow row) => row._debugInteractive);
  }

648
  static final LocalKey _headingRowKey = UniqueKey();
649

650 651 652 653
  void _handleSelectAll(bool? checked, bool someChecked) {
    // If some checkboxes are checked, all checkboxes are selected. Otherwise,
    // use the new checked value but default to false if it's null.
    final bool effectiveChecked = someChecked || (checked ?? false);
654
    if (onSelectAll != null) {
655
      onSelectAll!(effectiveChecked);
656
    } else {
657
      for (final DataRow row in rows) {
658
        if (row.onSelectChanged != null && row.selected != effectiveChecked) {
659
          row.onSelectChanged!(effectiveChecked);
660
        }
661
      }
662 663 664
    }
  }

665 666 667 668 669 670 671 672 673 674 675
  /// The default height of the heading row.
  static const double _headingRowHeight = 56.0;

  /// The default horizontal margin between the edges of the table and the content
  /// in the first and last cells of each row.
  static const double _horizontalMargin = 24.0;

  /// The default horizontal margin between the contents of each data column.
  static const double _columnSpacing = 56.0;

  /// The default padding between the heading content and sort arrow.
676
  static const double _sortArrowPadding = 2.0;
677 678 679 680

  /// The default divider thickness.
  static const double _dividerThickness = 1.0;

681
  static const Duration _sortArrowAnimationDuration = Duration(milliseconds: 150);
682 683

  Widget _buildCheckbox({
684
    required BuildContext context,
685
    required bool? checked,
686 687 688
    required VoidCallback? onRowTap,
    required ValueChanged<bool?>? onCheckboxChanged,
    required MaterialStateProperty<Color?>? overlayColor,
689
    required bool tristate,
690
  }) {
691
    final ThemeData themeData = Theme.of(context);
692 693 694
    final double effectiveHorizontalMargin = horizontalMargin
      ?? themeData.dataTableTheme.horizontalMargin
      ?? _horizontalMargin;
695 696 697 698 699 700
    final double effectiveCheckboxHorizontalMarginStart = checkboxHorizontalMargin
      ?? themeData.dataTableTheme.checkboxHorizontalMargin
      ?? effectiveHorizontalMargin;
    final double effectiveCheckboxHorizontalMarginEnd = checkboxHorizontalMargin
      ?? themeData.dataTableTheme.checkboxHorizontalMargin
      ?? effectiveHorizontalMargin / 2.0;
701
    Widget contents = Semantics(
702
      container: true,
703
      child: Padding(
704
        padding: EdgeInsetsDirectional.only(
705 706
          start: effectiveCheckboxHorizontalMarginStart,
          end: effectiveCheckboxHorizontalMarginEnd,
707
        ),
708 709
        child: Center(
          child: Checkbox(
710 711
            value: checked,
            onChanged: onCheckboxChanged,
712
            tristate: tristate,
713
          ),
714 715
        ),
      ),
716 717
    );
    if (onRowTap != null) {
718
      contents = TableRowInkWell(
719
        onTap: onRowTap,
720
        overlayColor: overlayColor,
721
        child: contents,
722 723
      );
    }
724
    return TableCell(
725
      verticalAlignment: TableCellVerticalAlignment.fill,
726
      child: contents,
727 728 729 730
    );
  }

  Widget _buildHeadingCell({
731 732 733 734 735 736 737 738 739
    required BuildContext context,
    required EdgeInsetsGeometry padding,
    required Widget label,
    required String? tooltip,
    required bool numeric,
    required VoidCallback? onSort,
    required bool sorted,
    required bool ascending,
    required MaterialStateProperty<Color?>? overlayColor,
740
  }) {
741
    final ThemeData themeData = Theme.of(context);
742
    final DataTableThemeData dataTableTheme = DataTableTheme.of(context);
743 744 745 746
    label = Row(
      textDirection: numeric ? TextDirection.rtl : null,
      children: <Widget>[
        label,
747 748 749 750 751 752 753 754 755
        if (onSort != null)
          ...<Widget>[
            _SortArrow(
              visible: sorted,
              up: sorted ? ascending : null,
              duration: _sortArrowAnimationDuration,
            ),
            const SizedBox(width: _sortArrowPadding),
          ],
756 757
      ],
    );
758 759

    final TextStyle effectiveHeadingTextStyle = headingTextStyle
760
      ?? dataTableTheme.headingTextStyle
761
      ?? themeData.dataTableTheme.headingTextStyle
762
      ?? themeData.textTheme.subtitle2!;
763
    final double effectiveHeadingRowHeight = headingRowHeight
764
      ?? dataTableTheme.headingRowHeight
765 766
      ?? themeData.dataTableTheme.headingRowHeight
      ?? _headingRowHeight;
767
    label = Container(
768
      padding: padding,
769
      height: effectiveHeadingRowHeight,
770
      alignment: numeric ? Alignment.centerRight : AlignmentDirectional.centerStart,
771
      child: AnimatedDefaultTextStyle(
772
        style: effectiveHeadingTextStyle,
773
        softWrap: false,
774
        duration: _sortArrowAnimationDuration,
775 776
        child: label,
      ),
777 778
    );
    if (tooltip != null) {
779
      label = Tooltip(
780
        message: tooltip,
781
        child: label,
782 783
      );
    }
784

785 786 787 788
    // TODO(dkwingsmt): Only wrap Inkwell if onSort != null. Blocked by
    // https://github.com/flutter/flutter/issues/51152
    label = InkWell(
      onTap: onSort,
789
      overlayColor: overlayColor,
790 791
      child: label,
    );
792 793 794 795
    return label;
  }

  Widget _buildDataCell({
796 797 798 799 800 801
    required BuildContext context,
    required EdgeInsetsGeometry padding,
    required Widget label,
    required bool numeric,
    required bool placeholder,
    required bool showEditIcon,
802
    required GestureTapCallback? onTap,
803
    required VoidCallback? onSelectChanged,
804 805 806 807
    required GestureTapCallback? onDoubleTap,
    required GestureLongPressCallback? onLongPress,
    required GestureTapDownCallback? onTapDown,
    required GestureTapCancelCallback? onTapCancel,
808
    required MaterialStateProperty<Color?>? overlayColor,
809
    required GestureLongPressCallback? onRowLongPress,
810
  }) {
811
    final ThemeData themeData = Theme.of(context);
812
    final DataTableThemeData dataTableTheme = DataTableTheme.of(context);
813
    if (showEditIcon) {
814
      const Widget icon = Icon(Icons.edit, size: 18.0);
815 816
      label = Expanded(child: label);
      label = Row(
817 818 819
        textDirection: numeric ? TextDirection.rtl : null,
        children: <Widget>[ label, icon ],
      );
820
    }
821 822

    final TextStyle effectiveDataTextStyle = dataTextStyle
823
      ?? dataTableTheme.dataTextStyle
824
      ?? themeData.dataTableTheme.dataTextStyle
825
      ?? themeData.textTheme.bodyText2!;
826
    final double effectiveDataRowHeight = dataRowHeight
827
      ?? dataTableTheme.dataRowHeight
828 829
      ?? themeData.dataTableTheme.dataRowHeight
      ?? kMinInteractiveDimension;
830
    label = Container(
831
      padding: padding,
832
      height: effectiveDataRowHeight,
833
      alignment: numeric ? Alignment.centerRight : AlignmentDirectional.centerStart,
834
      child: DefaultTextStyle(
835
        style: effectiveDataTextStyle.copyWith(
836
          color: placeholder ? effectiveDataTextStyle.color!.withOpacity(0.6) : null,
837
        ),
838
        child: DropdownButtonHideUnderline(child: label),
839
      ),
840
    );
841 842 843 844 845
    if (onTap != null ||
        onDoubleTap != null ||
        onLongPress != null ||
        onTapDown != null ||
        onTapCancel != null) {
846
      label = InkWell(
847
        onTap: onTap,
848 849 850 851
        onDoubleTap: onDoubleTap,
        onLongPress: onLongPress,
        onTapCancel: onTapCancel,
        onTapDown: onTapDown,
852
        overlayColor: overlayColor,
853
        child: label,
854
      );
855
    } else if (onSelectChanged != null || onRowLongPress != null) {
856
      label = TableRowInkWell(
857
        onTap: onSelectChanged,
858
        onLongPress: onRowLongPress,
859
        overlayColor: overlayColor,
860
        child: label,
861 862 863 864 865 866 867 868 869
      );
    }
    return label;
  }

  @override
  Widget build(BuildContext context) {
    assert(!_debugInteractive || debugCheckHasMaterial(context));

870
    final ThemeData theme = Theme.of(context);
871
    final DataTableThemeData dataTableTheme = DataTableTheme.of(context);
872
    final MaterialStateProperty<Color?>? effectiveHeadingRowColor = headingRowColor
873
      ?? dataTableTheme.headingRowColor
874
      ?? theme.dataTableTheme.headingRowColor;
875
    final MaterialStateProperty<Color?>? effectiveDataRowColor = dataRowColor
876
      ?? dataTableTheme.dataRowColor
877
      ?? theme.dataTableTheme.dataRowColor;
878
    final MaterialStateProperty<Color?> defaultRowColor = MaterialStateProperty.resolveWith(
879
      (Set<MaterialState> states) {
880
        if (states.contains(MaterialState.selected)) {
881
          return theme.colorScheme.primary.withOpacity(0.08);
882
        }
883 884
        return null;
      },
885
    );
886 887
    final bool anyRowSelectable = rows.any((DataRow row) => row.onSelectChanged != null);
    final bool displayCheckboxColumn = showCheckboxColumn && anyRowSelectable;
888 889 890 891
    final Iterable<DataRow> rowsWithCheckbox = displayCheckboxColumn ?
      rows.where((DataRow row) => row.onSelectChanged != null) : <DataRow>[];
    final Iterable<DataRow> rowsChecked = rowsWithCheckbox.where((DataRow row) => row.selected);
    final bool allChecked = displayCheckboxColumn && rowsChecked.length == rowsWithCheckbox.length;
892 893
    final bool anyChecked = displayCheckboxColumn && rowsChecked.isNotEmpty;
    final bool someChecked = anyChecked && !allChecked;
894
    final double effectiveHorizontalMargin = horizontalMargin
895
      ?? dataTableTheme.horizontalMargin
896 897
      ?? theme.dataTableTheme.horizontalMargin
      ?? _horizontalMargin;
898
    final double effectiveCheckboxHorizontalMarginStart = checkboxHorizontalMargin
899
      ?? dataTableTheme.checkboxHorizontalMargin
900 901 902
      ?? theme.dataTableTheme.checkboxHorizontalMargin
      ?? effectiveHorizontalMargin;
    final double effectiveCheckboxHorizontalMarginEnd = checkboxHorizontalMargin
903
      ?? dataTableTheme.checkboxHorizontalMargin
904 905
      ?? theme.dataTableTheme.checkboxHorizontalMargin
      ?? effectiveHorizontalMargin / 2.0;
906
    final double effectiveColumnSpacing = columnSpacing
907
      ?? dataTableTheme.columnSpacing
908 909
      ?? theme.dataTableTheme.columnSpacing
      ?? _columnSpacing;
910

911
    final List<TableColumnWidth> tableColumns = List<TableColumnWidth>.filled(columns.length + (displayCheckboxColumn ? 1 : 0), const _NullTableColumnWidth());
912
    final List<TableRow> tableRows = List<TableRow>.generate(
913 914
      rows.length + 1, // the +1 is for the header row
      (int index) {
915 916 917 918 919 920 921 922
        final bool isSelected = index > 0 && rows[index - 1].selected;
        final bool isDisabled = index > 0 && anyRowSelectable && rows[index - 1].onSelectChanged == null;
        final Set<MaterialState> states = <MaterialState>{
          if (isSelected)
            MaterialState.selected,
          if (isDisabled)
            MaterialState.disabled,
        };
923 924 925
        final Color? resolvedDataRowColor = index > 0 ? (rows[index - 1].color ?? effectiveDataRowColor)?.resolve(states) : null;
        final Color? resolvedHeadingRowColor = effectiveHeadingRowColor?.resolve(<MaterialState>{});
        final Color? rowColor = index > 0 ? resolvedDataRowColor : resolvedHeadingRowColor;
926 927 928
        final BorderSide borderSide = Divider.createBorderSide(
          context,
          width: dividerThickness
929
            ?? dataTableTheme.dividerThickness
930 931 932
            ?? theme.dataTableTheme.dividerThickness
            ?? _dividerThickness,
        );
933
        final Border? border = showBottomBorder
934 935
          ? Border(bottom: borderSide)
          : index == 0 ? null : Border(top: borderSide);
936
        return TableRow(
937
          key: index == 0 ? _headingRowKey : rows[index - 1].key,
938
          decoration: BoxDecoration(
939
            border: border,
940 941
            color: rowColor ?? defaultRowColor.resolve(states),
          ),
942
          children: List<Widget>.filled(tableColumns.length, const _NullWidget()),
943
        );
944
      },
945 946 947 948 949
    );

    int rowIndex;

    int displayColumnIndex = 0;
950
    if (displayCheckboxColumn) {
951
      tableColumns[0] = FixedColumnWidth(effectiveCheckboxHorizontalMarginStart + Checkbox.width + effectiveCheckboxHorizontalMarginEnd);
952
      tableRows[0].children![0] = _buildCheckbox(
953
        context: context,
954
        checked: someChecked ? null : allChecked,
955
        onRowTap: null,
956
        onCheckboxChanged: (bool? checked) => _handleSelectAll(checked, someChecked),
957
        overlayColor: null,
958
        tristate: true,
959 960
      );
      rowIndex = 1;
961
      for (final DataRow row in rows) {
962
        tableRows[rowIndex].children![0] = _buildCheckbox(
963
          context: context,
964
          checked: row.selected,
965
          onRowTap: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected),
966
          onCheckboxChanged: row.onSelectChanged,
967
          overlayColor: row.color ?? effectiveDataRowColor,
968
          tristate: false,
969 970 971 972 973 974 975
        );
        rowIndex += 1;
      }
      displayColumnIndex += 1;
    }

    for (int dataColumnIndex = 0; dataColumnIndex < columns.length; dataColumnIndex += 1) {
976
      final DataColumn column = columns[dataColumnIndex];
977

978
      final double paddingStart;
979 980 981
      if (dataColumnIndex == 0 && displayCheckboxColumn && checkboxHorizontalMargin != null) {
        paddingStart = effectiveHorizontalMargin;
      } else if (dataColumnIndex == 0 && displayCheckboxColumn) {
982
        paddingStart = effectiveHorizontalMargin / 2.0;
983
      } else if (dataColumnIndex == 0 && !displayCheckboxColumn) {
984
        paddingStart = effectiveHorizontalMargin;
985
      } else {
986
        paddingStart = effectiveColumnSpacing / 2.0;
987 988
      }

989
      final double paddingEnd;
990
      if (dataColumnIndex == columns.length - 1) {
991
        paddingEnd = effectiveHorizontalMargin;
992
      } else {
993
        paddingEnd = effectiveColumnSpacing / 2.0;
994 995
      }

996
      final EdgeInsetsDirectional padding = EdgeInsetsDirectional.only(
997 998
        start: paddingStart,
        end: paddingEnd,
999 1000 1001 1002 1003 1004
      );
      if (dataColumnIndex == _onlyTextColumn) {
        tableColumns[displayColumnIndex] = const IntrinsicColumnWidth(flex: 1.0);
      } else {
        tableColumns[displayColumnIndex] = const IntrinsicColumnWidth();
      }
1005
      tableRows[0].children![displayColumnIndex] = _buildHeadingCell(
1006
        context: context,
1007 1008 1009 1010
        padding: padding,
        label: column.label,
        tooltip: column.tooltip,
        numeric: column.numeric,
1011
        onSort: column.onSort != null ? () => column.onSort!(dataColumnIndex, sortColumnIndex != dataColumnIndex || !sortAscending) : null,
1012
        sorted: dataColumnIndex == sortColumnIndex,
1013
        ascending: sortAscending,
1014
        overlayColor: effectiveHeadingRowColor,
1015 1016
      );
      rowIndex = 1;
1017
      for (final DataRow row in rows) {
1018
        final DataCell cell = row.cells[dataColumnIndex];
1019
        tableRows[rowIndex].children![displayColumnIndex] = _buildDataCell(
Ian Hickson's avatar
Ian Hickson committed
1020
          context: context,
1021
          padding: padding,
1022
          label: cell.child,
1023 1024 1025 1026
          numeric: column.numeric,
          placeholder: cell.placeholder,
          showEditIcon: cell.showEditIcon,
          onTap: cell.onTap,
1027 1028 1029 1030
          onDoubleTap: cell.onDoubleTap,
          onLongPress: cell.onLongPress,
          onTapCancel: cell.onTapCancel,
          onTapDown: cell.onTapDown,
1031
          onSelectChanged: row.onSelectChanged == null ? null : () => row.onSelectChanged?.call(!row.selected),
1032
          overlayColor: row.color ?? effectiveDataRowColor,
1033
          onRowLongPress: row.onLongPress,
1034 1035 1036 1037 1038 1039
        );
        rowIndex += 1;
      }
      displayColumnIndex += 1;
    }

1040
    return Container(
1041
      decoration: decoration ?? dataTableTheme.decoration ?? theme.dataTableTheme.decoration,
1042 1043 1044 1045 1046
      child: Material(
        type: MaterialType.transparency,
        child: Table(
          columnWidths: tableColumns.asMap(),
          children: tableRows,
1047
          border: border,
1048 1049
        ),
      ),
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059
    );
  }
}

/// A rectangular area of a Material that responds to touch but clips
/// its ink splashes to the current table row of the nearest table.
///
/// Must have an ancestor [Material] widget in which to cause ink
/// reactions and an ancestor [Table] widget to establish a row.
///
1060
/// The [TableRowInkWell] must be in the same coordinate space (modulo
1061 1062 1063 1064
/// translations) as the [Table]. If it's rotated or scaled or
/// otherwise transformed, it will not be able to describe the
/// rectangle of the row in its own coordinate system as a [Rect], and
/// thus the splash will not occur. (In general, this is easy to
1065
/// achieve: just put the [TableRowInkWell] as the direct child of the
1066
/// [Table], and put the other contents of the cell inside it.)
1067 1068 1069 1070 1071 1072
///
/// See also:
///
///  * [DataTable], which makes use of [TableRowInkWell] when
///    [DataRow.onSelectChanged] is defined and [DataCell.onTap]
///    is not.
1073
class TableRowInkWell extends InkResponse {
1074
  /// Creates an ink well for a table row.
1075
  const TableRowInkWell({
1076 1077 1078 1079 1080 1081 1082
    super.key,
    super.child,
    super.onTap,
    super.onDoubleTap,
    super.onLongPress,
    super.onHighlightChanged,
    super.overlayColor,
1083 1084
  }) : super(
    containedInkWell: true,
1085
    highlightShape: BoxShape.rectangle,
1086 1087 1088 1089 1090 1091
  );

  @override
  RectCallback getRectCallback(RenderBox referenceBox) {
    return () {
      RenderObject cell = referenceBox;
1092
      AbstractNode? table = cell.parent;
1093
      final Matrix4 transform = Matrix4.identity();
1094
      while (table is RenderObject && table is! RenderTable) {
1095
        table.applyPaintTransform(cell, transform);
1096
        assert(table == cell.parent);
1097
        cell = table;
1098 1099 1100
        table = table.parent;
      }
      if (table is RenderTable) {
1101
        final TableCellParentData cellParentData = cell.parentData! as TableCellParentData;
1102
        assert(cellParentData.y != null);
1103
        final Rect rect = table.getRowBox(cellParentData.y!);
1104
        // The rect is in the table's coordinate space. We need to change it to the
1105
        // TableRowInkWell's coordinate space.
1106
        table.applyPaintTransform(cell, transform);
1107
        final Offset? offset = MatrixUtils.getAsTranslation(transform);
1108
        if (offset != null) {
1109
          return rect.shift(-offset);
1110
        }
1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
      }
      return Rect.zero;
    };
  }

  @override
  bool debugCheckContext(BuildContext context) {
    assert(debugCheckHasTable(context));
    return super.debugCheckContext(context);
  }
}

class _SortArrow extends StatefulWidget {
1124
  const _SortArrow({
1125 1126 1127
    required this.visible,
    required this.up,
    required this.duration,
1128
  });
1129 1130 1131

  final bool visible;

1132
  final bool? up;
1133 1134 1135 1136

  final Duration duration;

  @override
1137
  _SortArrowState createState() => _SortArrowState();
1138 1139
}

1140
class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
1141 1142
  late AnimationController _opacityController;
  late Animation<double> _opacityAnimation;
1143

1144 1145
  late AnimationController _orientationController;
  late Animation<double> _orientationAnimation;
1146 1147
  double _orientationOffset = 0.0;

1148
  bool? _up;
1149

1150 1151 1152
  static final Animatable<double> _turnTween = Tween<double>(begin: 0.0, end: math.pi)
    .chain(CurveTween(curve: Curves.easeIn));

1153 1154 1155
  @override
  void initState() {
    super.initState();
1156
    _up = widget.up;
1157 1158
    _opacityAnimation = CurvedAnimation(
      parent: _opacityController = AnimationController(
1159
        duration: widget.duration,
1160
        vsync: this,
1161
      ),
1162
      curve: Curves.fastOutSlowIn,
1163 1164
    )
    ..addListener(_rebuild);
1165
    _opacityController.value = widget.visible ? 1.0 : 0.0;
1166 1167 1168 1169 1170 1171 1172
    _orientationController = AnimationController(
      duration: widget.duration,
      vsync: this,
    );
    _orientationAnimation = _orientationController.drive(_turnTween)
      ..addListener(_rebuild)
      ..addStatusListener(_resetOrientationAnimation);
1173
    if (widget.visible) {
1174
      _orientationOffset = widget.up! ? 0.0 : math.pi;
1175
    }
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
  }

  void _rebuild() {
    setState(() {
      // The animations changed, so we need to rebuild.
    });
  }

  void _resetOrientationAnimation(AnimationStatus status) {
    if (status == AnimationStatus.completed) {
1186 1187
      assert(_orientationAnimation.value == math.pi);
      _orientationOffset += math.pi;
1188 1189 1190 1191 1192
      _orientationController.value = 0.0; // TODO(ianh): This triggers a pointless rebuild.
    }
  }

  @override
1193 1194
  void didUpdateWidget(_SortArrow oldWidget) {
    super.didUpdateWidget(oldWidget);
1195
    bool skipArrow = false;
1196
    final bool? newUp = widget.up ?? _up;
1197 1198
    if (oldWidget.visible != widget.visible) {
      if (widget.visible && (_opacityController.status == AnimationStatus.dismissed)) {
1199 1200
        _orientationController.stop();
        _orientationController.value = 0.0;
1201
        _orientationOffset = newUp! ? 0.0 : math.pi;
1202 1203
        skipArrow = true;
      }
1204
      if (widget.visible) {
1205 1206
        _opacityController.forward();
      } else {
1207
        _opacityController.reverse();
1208 1209
      }
    }
1210
    if ((_up != newUp) && !skipArrow) {
1211 1212 1213 1214 1215 1216
      if (_orientationController.status == AnimationStatus.dismissed) {
        _orientationController.forward();
      } else {
        _orientationController.reverse();
      }
    }
1217
    _up = newUp;
1218 1219 1220 1221 1222 1223 1224 1225 1226
  }

  @override
  void dispose() {
    _opacityController.dispose();
    _orientationController.dispose();
    super.dispose();
  }

1227 1228
  static const double _arrowIconBaselineOffset = -1.5;
  static const double _arrowIconSize = 16.0;
1229 1230 1231

  @override
  Widget build(BuildContext context) {
1232 1233
    return FadeTransition(
      opacity: _opacityAnimation,
1234 1235
      child: Transform(
        transform: Matrix4.rotationZ(_orientationOffset + _orientationAnimation.value)
1236
                             ..setTranslationRaw(0.0, _arrowIconBaselineOffset, 0.0),
1237
        alignment: Alignment.center,
1238
        child: const Icon(
1239
          Icons.arrow_upward,
1240
          size: _arrowIconSize,
1241 1242
        ),
      ),
1243 1244
    );
  }
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
}

class _NullTableColumnWidth extends TableColumnWidth {
  const _NullTableColumnWidth();

  @override
  double maxIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) => throw UnimplementedError();

  @override
  double minIntrinsicWidth(Iterable<RenderBox> cells, double containerWidth) => throw UnimplementedError();
}

class _NullWidget extends Widget {
  const _NullWidget();
1259

1260 1261
  @override
  Element createElement() => throw UnimplementedError();
1262
}