Unverified Commit 53173309 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Remove the defaults for textBaseline (#68646)

parent 246bf60f
...@@ -14,6 +14,8 @@ import 'table_border.dart'; ...@@ -14,6 +14,8 @@ import 'table_border.dart';
/// Parent data used by [RenderTable] for its children. /// Parent data used by [RenderTable] for its children.
class TableCellParentData extends BoxParentData { class TableCellParentData extends BoxParentData {
/// Where this cell should be placed vertically. /// Where this cell should be placed vertically.
///
/// When using [TableCellVerticalAlignment.baseline], the text baseline must be set as well.
TableCellVerticalAlignment? verticalAlignment; TableCellVerticalAlignment? verticalAlignment;
/// The column that the child was in the last time it was laid out. /// The column that the child was in the last time it was laid out.
...@@ -1049,7 +1051,7 @@ class RenderTable extends RenderBox { ...@@ -1049,7 +1051,7 @@ class RenderTable extends RenderBox {
childParentData.y = y; childParentData.y = y;
switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) { switch (childParentData.verticalAlignment ?? defaultVerticalAlignment) {
case TableCellVerticalAlignment.baseline: case TableCellVerticalAlignment.baseline:
assert(textBaseline != null); assert(textBaseline != null, 'An explicit textBaseline is required when using baseline alignment.');
child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true); child.layout(BoxConstraints.tightFor(width: widths[x]), parentUsesSize: true);
final double? childBaseline = child.getDistanceToBaseline(textBaseline!, onlyReal: true); final double? childBaseline = child.getDistanceToBaseline(textBaseline!, onlyReal: true);
if (childBaseline != null) { if (childBaseline != null) {
......
...@@ -3966,7 +3966,7 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -3966,7 +3966,7 @@ class Flex extends MultiChildRenderObjectWidget {
this.crossAxisAlignment = CrossAxisAlignment.center, this.crossAxisAlignment = CrossAxisAlignment.center,
this.textDirection, this.textDirection,
this.verticalDirection = VerticalDirection.down, this.verticalDirection = VerticalDirection.down,
this.textBaseline = TextBaseline.alphabetic, this.textBaseline, // NO DEFAULT: we don't know what the text's baseline should be
this.clipBehavior = Clip.none, this.clipBehavior = Clip.none,
List<Widget> children = const <Widget>[], List<Widget> children = const <Widget>[],
}) : assert(direction != null), }) : assert(direction != null),
...@@ -4064,7 +4064,8 @@ class Flex extends MultiChildRenderObjectWidget { ...@@ -4064,7 +4064,8 @@ class Flex extends MultiChildRenderObjectWidget {
/// If aligning items according to their baseline, which baseline to use. /// If aligning items according to their baseline, which baseline to use.
/// ///
/// Defaults to [TextBaseline.alphabetic]. /// This must be set if using baseline alignment. There is no default because there is no
/// way for the framework to know the correct baseline _a priori_.
final TextBaseline? textBaseline; final TextBaseline? textBaseline;
/// {@macro flutter.widgets.Clip} /// {@macro flutter.widgets.Clip}
...@@ -4341,7 +4342,7 @@ class Row extends Flex { ...@@ -4341,7 +4342,7 @@ class Row extends Flex {
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center, CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
TextDirection? textDirection, TextDirection? textDirection,
VerticalDirection verticalDirection = VerticalDirection.down, VerticalDirection verticalDirection = VerticalDirection.down,
TextBaseline textBaseline = TextBaseline.alphabetic, TextBaseline? textBaseline, // NO DEFAULT: we don't know what the text's baseline should be
List<Widget> children = const <Widget>[], List<Widget> children = const <Widget>[],
}) : super( }) : super(
children: children, children: children,
......
...@@ -116,10 +116,11 @@ class Table extends RenderObjectWidget { ...@@ -116,10 +116,11 @@ class Table extends RenderObjectWidget {
this.textDirection, this.textDirection,
this.border, this.border,
this.defaultVerticalAlignment = TableCellVerticalAlignment.top, this.defaultVerticalAlignment = TableCellVerticalAlignment.top,
this.textBaseline = TextBaseline.alphabetic, this.textBaseline, // NO DEFAULT: we don't know what the text's baseline should be
}) : assert(children != null), }) : assert(children != null),
assert(defaultColumnWidth != null), assert(defaultColumnWidth != null),
assert(defaultVerticalAlignment != null), assert(defaultVerticalAlignment != null),
assert(defaultVerticalAlignment != TableCellVerticalAlignment.baseline || textBaseline != null, 'textBaseline is required if you specify the defaultVerticalAlignment with TableCellVerticalAlignment.baseline'),
assert(() { assert(() {
if (children.any((TableRow row) => row.children == null)) { if (children.any((TableRow row) => row.children == null)) {
throw FlutterError( throw FlutterError(
...@@ -231,8 +232,9 @@ class Table extends RenderObjectWidget { ...@@ -231,8 +232,9 @@ class Table extends RenderObjectWidget {
/// The text baseline to use when aligning rows using [TableCellVerticalAlignment.baseline]. /// The text baseline to use when aligning rows using [TableCellVerticalAlignment.baseline].
/// ///
/// Defaults to [TextBaseline.alphabetic]. /// This must be set if using baseline alignment. There is no default because there is no
final TextBaseline textBaseline; /// way for the framework to know the correct baseline _a priori_.
final TextBaseline? textBaseline;
final List<Decoration?>? _rowDecorations; final List<Decoration?>? _rowDecorations;
......
...@@ -32,8 +32,8 @@ void main() { ...@@ -32,8 +32,8 @@ void main() {
' If multiple keyed nodes exist as children of another node, they\n' ' If multiple keyed nodes exist as children of another node, they\n'
' must have unique keys.\n' ' must have unique keys.\n'
' Flex(direction: vertical, mainAxisAlignment: start,\n' ' Flex(direction: vertical, mainAxisAlignment: start,\n'
' crossAxisAlignment: center, textBaseline: alphabetic) has\n' ' crossAxisAlignment: center) has multiple children with key\n'
" multiple children with key [<'key'>].\n", ' [<\'key\'>].\n',
), ),
); );
} }
......
...@@ -930,29 +930,15 @@ void main() { ...@@ -930,29 +930,15 @@ void main() {
}, },
); );
testWidgets( testWidgets('Table widget - Default textBaseline is null', (WidgetTester tester) async {
'Table widget - Default textBaseline is set to TableBaseline.alphabetic', expect(
(WidgetTester tester) async { () => Table(defaultVerticalAlignment: TableCellVerticalAlignment.baseline),
await tester.pumpWidget( throwsA(
Directionality( isAssertionError
textDirection: TextDirection.ltr, .having((AssertionError error) => error.message, 'exception message', contains('baseline')),
child: Table( ),
defaultVerticalAlignment: TableCellVerticalAlignment.baseline, );
children: const <TableRow>[ });
TableRow(
children: <Widget>[
Text('Some Text'),
],
),
],
),
),
);
final RenderTable table = tester.renderObject(find.byType(Table));
expect(table.textBaseline, TextBaseline.alphabetic);
},
);
testWidgets( testWidgets(
'Table widget requires all TableRows to have non-null children', 'Table widget requires all TableRows to have non-null children',
......
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