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

The overflow indicator was sharing the same `TextPainter`.
This commit is contained in:
LongCatIsLooong 2024-03-14 09:43:00 -07:00 committed by GitHub
parent 51d59a7d1e
commit a69567a36f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 2 deletions

View file

@ -1659,6 +1659,7 @@ class TextPainter {
///
/// After disposal this painter is unusable.
void dispose() {
assert(!debugDisposed);
assert(() {
_disposed = true;
return true;

View file

@ -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

View file

@ -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);