Unverified Commit 50ecd570 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

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

parent a4ec6278
...@@ -23,6 +23,8 @@ const TextStyle _kTextStyle = TextStyle( ...@@ -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 { ...@@ -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 { ...@@ -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;
} }
......
...@@ -280,4 +280,19 @@ void main() { ...@@ -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,
);
});
} }
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