Unverified Commit fb9ff62c authored by LongCatIsLooong's avatar LongCatIsLooong Committed by GitHub

InputDecorator negative baseline error message (#74837)

parent 52e90f55
...@@ -935,9 +935,20 @@ class _RenderDecoration extends RenderBox { ...@@ -935,9 +935,20 @@ class _RenderDecoration extends RenderBox {
// baseline from the alphabetic baseline. The ideographic baseline is for // baseline from the alphabetic baseline. The ideographic baseline is for
// use post-layout and is derived from the alphabetic baseline combined with // use post-layout and is derived from the alphabetic baseline combined with
// the font metrics. // the font metrics.
final double? baseline = box.getDistanceToBaseline(TextBaseline.alphabetic); final double baseline = box.getDistanceToBaseline(TextBaseline.alphabetic)!;
assert(baseline != null && baseline >= 0.0);
return baseline!; assert(() {
if (baseline >= 0)
return true;
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary("One of InputDecorator's children reported a negative baseline offset."),
ErrorDescription(
'${box.runtimeType}, of size ${box.size}, reported a negative '
'alphabetic baseline of $baseline.',
),
]);
}());
return baseline;
} }
// Returns a value used by performLayout to position all of the renderers. // Returns a value used by performLayout to position all of the renderers.
...@@ -1767,7 +1778,9 @@ class _AffixText extends StatelessWidget { ...@@ -1767,7 +1778,9 @@ class _AffixText extends StatelessWidget {
/// [InputDecorator] can be used to create widgets that look and behave like a /// [InputDecorator] can be used to create widgets that look and behave like a
/// [TextField] but support other kinds of input. /// [TextField] but support other kinds of input.
/// ///
/// Requires one of its ancestors to be a [Material] widget. /// Requires one of its ancestors to be a [Material] widget. The [child] widget,
/// as well as the decorative widgets specified in [decoration], must have
/// non-negative baselines.
/// ///
/// See also: /// See also:
/// ///
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
...@@ -4420,4 +4421,42 @@ void main() { ...@@ -4420,4 +4421,42 @@ void main() {
final double intrinsicHeight = tester.getSize(find.byKey(intrinsicHeightKey)).height; final double intrinsicHeight = tester.getSize(find.byKey(intrinsicHeightKey)).height;
expect(intrinsicHeight, equals(height)); expect(intrinsicHeight, equals(height));
}); });
testWidgets('error message for negative baseline', (WidgetTester tester) async {
FlutterErrorDetails? errorDetails;
final FlutterExceptionHandler? oldHandler = FlutterError.onError;
FlutterError.onError = (FlutterErrorDetails details) {
errorDetails ??= details;
};
try {
await tester.pumpWidget(
MaterialApp(
home: Center(
child: Directionality(
textDirection: TextDirection.ltr,
child: InputDecorator(
decoration: const InputDecoration(),
child: Stack(
children: const <Widget>[
SizedBox(height: 0),
Positioned(
bottom: 5,
child: Text('ok'),
),
],
),
),
),
),
),
null,
EnginePhase.layout,
);
} finally {
FlutterError.onError = oldHandler;
}
expect(errorDetails?.toString(), contains("InputDecorator's children reported a negative baseline"));
expect(errorDetails?.toString(), contains('RenderStack'));
});
} }
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