mirror of
https://github.com/flutter/flutter
synced 2024-08-25 02:46:31 +00:00
Asserts if a TextPainter
gets disposed more than once (#145124)
The overflow indicator was sharing the same `TextPainter`.
This commit is contained in:
parent
51d59a7d1e
commit
a69567a36f
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue