Commit 260353f2 authored by Adam Barth's avatar Adam Barth Committed by GitHub

RTL support for DataTable (#12229)

Just some very minor tweaks to remove subtle LTR bias.

We use the same arrow rotation animation in RTL and LTR, but I think
that's correct. Usually, rotations are either clockwise or
anitclockwise, which are the same in RTL and LTR. We might need to check
with someone who reads an RTL language to confirm.

Fixes #11845
parent 78a29260
...@@ -36,7 +36,7 @@ class DataColumn { ...@@ -36,7 +36,7 @@ class DataColumn {
@required this.label, @required this.label,
this.tooltip, this.tooltip,
this.numeric: false, this.numeric: false,
this.onSort this.onSort,
}) : assert(label != null); }) : assert(label != null);
/// The column heading. /// The column heading.
...@@ -88,7 +88,7 @@ class DataRow { ...@@ -88,7 +88,7 @@ class DataRow {
this.key, this.key,
this.selected: false, this.selected: false,
this.onSelectChanged, this.onSelectChanged,
@required this.cells @required this.cells,
}) : assert(cells != null); }) : assert(cells != null);
/// Creates the configuration for a row of a [DataTable], deriving /// Creates the configuration for a row of a [DataTable], deriving
...@@ -99,7 +99,7 @@ class DataRow { ...@@ -99,7 +99,7 @@ class DataRow {
int index, int index,
this.selected: false, this.selected: false,
this.onSelectChanged, this.onSelectChanged,
@required this.cells @required this.cells,
}) : assert(cells != null), }) : assert(cells != null),
key = new ValueKey<int>(index); key = new ValueKey<int>(index);
...@@ -258,7 +258,7 @@ class DataTable extends StatelessWidget { ...@@ -258,7 +258,7 @@ class DataTable extends StatelessWidget {
this.sortColumnIndex, this.sortColumnIndex,
this.sortAscending: true, this.sortAscending: true,
this.onSelectAll, this.onSelectAll,
@required this.rows @required this.rows,
}) : assert(columns != null), }) : assert(columns != null),
assert(columns.isNotEmpty), assert(columns.isNotEmpty),
assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)), assert(sortColumnIndex == null || (sortColumnIndex >= 0 && sortColumnIndex < columns.length)),
...@@ -367,19 +367,19 @@ class DataTable extends StatelessWidget { ...@@ -367,19 +367,19 @@ class DataTable extends StatelessWidget {
child: new Checkbox( child: new Checkbox(
activeColor: color, activeColor: color,
value: checked, value: checked,
onChanged: onCheckboxChanged onChanged: onCheckboxChanged,
) ),
) ),
); );
if (onRowTap != null) { if (onRowTap != null) {
contents = new TableRowInkWell( contents = new TableRowInkWell(
onTap: onRowTap, onTap: onRowTap,
child: contents child: contents,
); );
} }
return new TableCell( return new TableCell(
verticalAlignment: TableCellVerticalAlignment.fill, verticalAlignment: TableCellVerticalAlignment.fill,
child: contents child: contents,
); );
} }
...@@ -391,18 +391,18 @@ class DataTable extends StatelessWidget { ...@@ -391,18 +391,18 @@ class DataTable extends StatelessWidget {
bool numeric, bool numeric,
VoidCallback onSort, VoidCallback onSort,
bool sorted, bool sorted,
bool ascending bool ascending,
}) { }) {
if (onSort != null) { if (onSort != null) {
final Widget arrow = new _SortArrow( final Widget arrow = new _SortArrow(
visible: sorted, visible: sorted,
down: sorted ? ascending : null, down: sorted ? ascending : null,
duration: _kSortArrowAnimationDuration duration: _kSortArrowAnimationDuration,
); );
final Widget arrowPadding = const SizedBox(width: _kSortArrowPadding); final Widget arrowPadding = const SizedBox(width: _kSortArrowPadding);
label = new Row( label = new Row(
children: numeric ? <Widget>[ arrow, arrowPadding, label ] textDirection: numeric ? TextDirection.rtl : null,
: <Widget>[ label, arrowPadding, arrow ] children: <Widget>[ label, arrowPadding, arrow ],
); );
} }
label = new Container( label = new Container(
...@@ -417,23 +417,22 @@ class DataTable extends StatelessWidget { ...@@ -417,23 +417,22 @@ class DataTable extends StatelessWidget {
height: _kHeadingRowHeight / _kHeadingFontSize, height: _kHeadingRowHeight / _kHeadingFontSize,
color: (Theme.of(context).brightness == Brightness.light) color: (Theme.of(context).brightness == Brightness.light)
? ((onSort != null && sorted) ? Colors.black87 : Colors.black54) ? ((onSort != null && sorted) ? Colors.black87 : Colors.black54)
: ((onSort != null && sorted) ? Colors.white : Colors.white70) : ((onSort != null && sorted) ? Colors.white : Colors.white70),
), ),
duration: _kSortArrowAnimationDuration, duration: _kSortArrowAnimationDuration,
child: label child: label,
) ),
); );
if (tooltip != null) { if (tooltip != null) {
label = new Tooltip( label = new Tooltip(
message: tooltip, message: tooltip,
child: label child: label,
); );
} }
if (onSort != null) { if (onSort != null) {
label = new InkWell( label = new InkWell(
onTap: onSort, onTap: onSort,
// TODO(ianh): When we do RTL, we need to use 'end' ordering for the non-numeric case child: label,
child: label
); );
} }
return label; return label;
...@@ -447,13 +446,16 @@ class DataTable extends StatelessWidget { ...@@ -447,13 +446,16 @@ class DataTable extends StatelessWidget {
bool placeholder, bool placeholder,
bool showEditIcon, bool showEditIcon,
VoidCallback onTap, VoidCallback onTap,
VoidCallback onSelectChanged VoidCallback onSelectChanged,
}) { }) {
final bool isLightTheme = Theme.of(context).brightness == Brightness.light; final bool isLightTheme = Theme.of(context).brightness == Brightness.light;
if (showEditIcon) { if (showEditIcon) {
final Widget icon = const Icon(Icons.edit, size: 18.0); final Widget icon = const Icon(Icons.edit, size: 18.0);
label = new Expanded(child: label); label = new Expanded(child: label);
label = new Row(children: numeric ? <Widget>[ icon, label ] : <Widget>[ label, icon ]); label = new Row(
textDirection: numeric ? TextDirection.rtl : null,
children: <Widget>[ label, icon ],
);
} }
label = new Container( label = new Container(
padding: padding, padding: padding,
...@@ -465,25 +467,25 @@ class DataTable extends StatelessWidget { ...@@ -465,25 +467,25 @@ class DataTable extends StatelessWidget {
fontSize: 13.0, fontSize: 13.0,
color: isLightTheme color: isLightTheme
? (placeholder ? Colors.black38 : Colors.black87) ? (placeholder ? Colors.black38 : Colors.black87)
: (placeholder ? Colors.white30 : Colors.white70) : (placeholder ? Colors.white30 : Colors.white70),
), ),
child: IconTheme.merge( child: IconTheme.merge(
data: new IconThemeData( data: new IconThemeData(
color: isLightTheme ? Colors.black54 : Colors.white70 color: isLightTheme ? Colors.black54 : Colors.white70,
), ),
child: new DropdownButtonHideUnderline(child: label) child: new DropdownButtonHideUnderline(child: label),
) )
) )
); );
if (onTap != null) { if (onTap != null) {
label = new InkWell( label = new InkWell(
onTap: onTap, onTap: onTap,
child: label child: label,
); );
} else if (onSelectChanged != null) { } else if (onSelectChanged != null) {
label = new TableRowInkWell( label = new TableRowInkWell(
onTap: onSelectChanged, onTap: onSelectChanged,
child: label child: label,
); );
} }
return label; return label;
...@@ -497,10 +499,10 @@ class DataTable extends StatelessWidget { ...@@ -497,10 +499,10 @@ class DataTable extends StatelessWidget {
final BoxDecoration _kSelectedDecoration = new BoxDecoration( final BoxDecoration _kSelectedDecoration = new BoxDecoration(
border: new Border(bottom: new BorderSide(color: theme.dividerColor)), border: new Border(bottom: new BorderSide(color: theme.dividerColor)),
// The backgroundColor has to be transparent so you can see the ink on the material // The backgroundColor has to be transparent so you can see the ink on the material
color: (Theme.of(context).brightness == Brightness.light) ? _kGrey100Opacity : _kGrey300Opacity color: (Theme.of(context).brightness == Brightness.light) ? _kGrey100Opacity : _kGrey300Opacity,
); );
final BoxDecoration _kUnselectedDecoration = new BoxDecoration( final BoxDecoration _kUnselectedDecoration = new BoxDecoration(
border: new Border(bottom: new BorderSide(color: theme.dividerColor)) border: new Border(bottom: new BorderSide(color: theme.dividerColor)),
); );
final bool showCheckboxColumn = rows.any((DataRow row) => row.onSelectChanged != null); final bool showCheckboxColumn = rows.any((DataRow row) => row.onSelectChanged != null);
...@@ -516,7 +518,7 @@ class DataTable extends StatelessWidget { ...@@ -516,7 +518,7 @@ class DataTable extends StatelessWidget {
: _kUnselectedDecoration, : _kUnselectedDecoration,
children: new List<Widget>(tableColumns.length) children: new List<Widget>(tableColumns.length)
); );
} },
); );
int rowIndex; int rowIndex;
...@@ -527,7 +529,7 @@ class DataTable extends StatelessWidget { ...@@ -527,7 +529,7 @@ class DataTable extends StatelessWidget {
tableRows[0].children[0] = _buildCheckbox( tableRows[0].children[0] = _buildCheckbox(
color: theme.accentColor, color: theme.accentColor,
checked: allChecked, checked: allChecked,
onCheckboxChanged: _handleSelectAll onCheckboxChanged: _handleSelectAll,
); );
rowIndex = 1; rowIndex = 1;
for (DataRow row in rows) { for (DataRow row in rows) {
...@@ -535,7 +537,7 @@ class DataTable extends StatelessWidget { ...@@ -535,7 +537,7 @@ class DataTable extends StatelessWidget {
color: theme.accentColor, color: theme.accentColor,
checked: row.selected, checked: row.selected,
onRowTap: () => row.onSelectChanged(!row.selected), onRowTap: () => row.onSelectChanged(!row.selected),
onCheckboxChanged: row.onSelectChanged onCheckboxChanged: row.onSelectChanged,
); );
rowIndex += 1; rowIndex += 1;
} }
...@@ -561,7 +563,7 @@ class DataTable extends StatelessWidget { ...@@ -561,7 +563,7 @@ class DataTable extends StatelessWidget {
numeric: column.numeric, numeric: column.numeric,
onSort: () => column.onSort(dataColumnIndex, sortColumnIndex == dataColumnIndex ? !sortAscending : true), onSort: () => column.onSort(dataColumnIndex, sortColumnIndex == dataColumnIndex ? !sortAscending : true),
sorted: dataColumnIndex == sortColumnIndex, sorted: dataColumnIndex == sortColumnIndex,
ascending: sortAscending ascending: sortAscending,
); );
rowIndex = 1; rowIndex = 1;
for (DataRow row in rows) { for (DataRow row in rows) {
...@@ -574,7 +576,7 @@ class DataTable extends StatelessWidget { ...@@ -574,7 +576,7 @@ class DataTable extends StatelessWidget {
placeholder: cell.placeholder, placeholder: cell.placeholder,
showEditIcon: cell.showEditIcon, showEditIcon: cell.showEditIcon,
onTap: cell.onTap, onTap: cell.onTap,
onSelectChanged: () => row.onSelectChanged(!row.selected) onSelectChanged: () => row.onSelectChanged(!row.selected),
); );
rowIndex += 1; rowIndex += 1;
} }
...@@ -609,7 +611,7 @@ class TableRowInkWell extends InkResponse { ...@@ -609,7 +611,7 @@ class TableRowInkWell extends InkResponse {
GestureTapCallback onTap, GestureTapCallback onTap,
GestureTapCallback onDoubleTap, GestureTapCallback onDoubleTap,
GestureLongPressCallback onLongPress, GestureLongPressCallback onLongPress,
ValueChanged<bool> onHighlightChanged ValueChanged<bool> onHighlightChanged,
}) : super( }) : super(
key: key, key: key,
child: child, child: child,
...@@ -618,7 +620,7 @@ class TableRowInkWell extends InkResponse { ...@@ -618,7 +620,7 @@ class TableRowInkWell extends InkResponse {
onLongPress: onLongPress, onLongPress: onLongPress,
onHighlightChanged: onHighlightChanged, onHighlightChanged: onHighlightChanged,
containedInkWell: true, containedInkWell: true,
highlightShape: BoxShape.rectangle highlightShape: BoxShape.rectangle,
); );
@override @override
...@@ -661,7 +663,7 @@ class _SortArrow extends StatefulWidget { ...@@ -661,7 +663,7 @@ class _SortArrow extends StatefulWidget {
Key key, Key key,
this.visible, this.visible,
this.down, this.down,
this.duration this.duration,
}) : super(key: key); }) : super(key: key);
final bool visible; final bool visible;
...@@ -699,7 +701,7 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin { ...@@ -699,7 +701,7 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
_opacityController.value = widget.visible ? 1.0 : 0.0; _opacityController.value = widget.visible ? 1.0 : 0.0;
_orientationAnimation = new Tween<double>( _orientationAnimation = new Tween<double>(
begin: 0.0, begin: 0.0,
end: math.PI end: math.PI,
).animate(new CurvedAnimation( ).animate(new CurvedAnimation(
parent: _orientationController = new AnimationController( parent: _orientationController = new AnimationController(
duration: widget.duration, duration: widget.duration,
...@@ -776,9 +778,9 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin { ...@@ -776,9 +778,9 @@ class _SortArrowState extends State<_SortArrow> with TickerProviderStateMixin {
child: new Icon( child: new Icon(
Icons.arrow_downward, Icons.arrow_downward,
size: _kArrowIconSize, size: _kArrowIconSize,
color: (Theme.of(context).brightness == Brightness.light) ? Colors.black87 : Colors.white70 color: (Theme.of(context).brightness == Brightness.light) ? Colors.black87 : Colors.white70,
) ),
) ),
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment