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

Asserts if a `TextPainter` gets disposed more than once (#145124)

The overflow indicator was sharing the same `TextPainter`.
parent 51d59a7d
......@@ -1659,6 +1659,7 @@ class TextPainter {
///
/// After disposal this painter is unusable.
void dispose() {
assert(!debugDisposed);
assert(() {
_disposed = true;
return true;
......
......@@ -109,9 +109,10 @@ mixin DebugOverflowIndicatorMixin on RenderObject {
);
static final Paint _labelBackgroundPaint = Paint()..color = const Color(0xFFFFFFFF);
final List<TextPainter> _indicatorLabel = List<TextPainter>.filled(
final List<TextPainter> _indicatorLabel = List<TextPainter>.generate(
_OverflowSide.values.length,
TextPainter(textDirection: TextDirection.ltr), // This label is in English.
(int i) => TextPainter(textDirection: TextDirection.ltr), // This label is in English.
growable: false,
);
@override
......
......@@ -1429,6 +1429,12 @@ void main() {
expect(painter.debugDisposed, true);
});
test('TextPainter - asserts if disposed more than once', () {
final TextPainter painter = TextPainter()..dispose();
expect(painter.debugDisposed, isTrue);
expect(painter.dispose, throwsAssertionError);
});
test('TextPainter computeWidth', () {
const InlineSpan text = TextSpan(text: 'foobar');
final TextPainter painter = TextPainter(text: text, textDirection: TextDirection.ltr);
......
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