Skip to content

Commit 50ecd57

Browse files
authored
BannerPainter should dispatch creation and disposal events. (flutter#137472)
1 parent a4ec627 commit 50ecd57

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/flutter/lib/src/widgets/banner.dart

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const TextStyle _kTextStyle = TextStyle(
2323
height: 1.0,
2424
);
2525

26+
const String _flutterWidgetsLibrary = 'package:flutter/widgets.dart';
27+
2628
/// Where to show a [Banner].
2729
///
2830
/// The start and end locations are relative to the ambient [Directionality]
@@ -61,7 +63,17 @@ class BannerPainter extends CustomPainter {
6163
required this.layoutDirection,
6264
this.color = _kColor,
6365
this.textStyle = _kTextStyle,
64-
}) : super(repaint: PaintingBinding.instance.systemFonts);
66+
}) : super(repaint: PaintingBinding.instance.systemFonts) {
67+
// TODO(polina-c): stop duplicating code across disposables
68+
// https://github.com/flutter/flutter/issues/137435
69+
if (kFlutterMemoryAllocationsEnabled) {
70+
MemoryAllocations.instance.dispatchObjectCreated(
71+
library: _flutterWidgetsLibrary,
72+
className: '$BannerPainter',
73+
object: this,
74+
);
75+
}
76+
}
6577

6678
/// The message to show in the banner.
6779
final String message;
@@ -117,6 +129,11 @@ class BannerPainter extends CustomPainter {
117129
///
118130
/// After calling this method, this object is no longer usable.
119131
void dispose() {
132+
// TODO(polina-c): stop duplicating code across disposables
133+
// https://github.com/flutter/flutter/issues/137435
134+
if (kFlutterMemoryAllocationsEnabled) {
135+
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
136+
}
120137
_textPainter?.dispose();
121138
_textPainter = null;
122139
}

packages/flutter/test/widgets/banner_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,19 @@ void main() {
280280
);
281281
debugDisableShadows = true;
282282
});
283+
284+
test('BannerPainter dispatches memory events', () async {
285+
await expectLater(
286+
await memoryEvents(
287+
() => BannerPainter(
288+
message: 'foo',
289+
textDirection: TextDirection.rtl,
290+
location: BannerLocation.topStart,
291+
layoutDirection: TextDirection.ltr,
292+
).dispose(),
293+
BannerPainter,
294+
),
295+
areCreateAndDispose,
296+
);
297+
});
283298
}

0 commit comments

Comments
 (0)