BannerPainter should dispatch creation and disposal events. (#137472)

This commit is contained in:
Kostia Sokolovskyi 2023-10-28 22:23:32 +02:00 committed by GitHub
parent a4ec6278b1
commit 50ecd5700f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 1 deletions

View File

@ -23,6 +23,8 @@ const TextStyle _kTextStyle = TextStyle(
height: 1.0, height: 1.0,
); );
const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart';
/// Where to show a [Banner]. /// Where to show a [Banner].
/// ///
/// The start and end locations are relative to the ambient [Directionality] /// The start and end locations are relative to the ambient [Directionality]
@ -61,7 +63,17 @@ class BannerPainter extends CustomPainter {
required this.layoutDirection, required this.layoutDirection,
this.color = _kColor, this.color = _kColor,
this.textStyle = _kTextStyle, this.textStyle = _kTextStyle,
}) : super(repaint: PaintingBinding.instance.systemFonts); }) : super(repaint: PaintingBinding.instance.systemFonts) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: _flutterWidgetsLibrary,
className: '$BannerPainter',
object: this,
);
}
}
/// The message to show in the banner. /// The message to show in the banner.
final String message; final String message;
@ -117,6 +129,11 @@ class BannerPainter extends CustomPainter {
/// ///
/// After calling this method, this object is no longer usable. /// After calling this method, this object is no longer usable.
void dispose() { void dispose() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_textPainter?.dispose(); _textPainter?.dispose();
_textPainter = null; _textPainter = null;
} }

View File

@ -280,4 +280,19 @@ void main() {
); );
debugDisableShadows = true; debugDisableShadows = true;
}); });
test('BannerPainter dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => BannerPainter(
message: 'foo',
textDirection: TextDirection.rtl,
location: BannerLocation.topStart,
layoutDirection: TextDirection.ltr,
).dispose(),
BannerPainter,
),
areCreateAndDispose,
);
});
} }