BannerPainter should dispatch creation and disposal events. (#137472)
This commit is contained in:
parent
a4ec6278b1
commit
50ecd5700f
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user