File tree Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Expand file tree Collapse file tree 2 files changed +30
-4
lines changed Original file line number Diff line number Diff line change @@ -198,9 +198,18 @@ abstract class Decoration with Diagnosticable {
198
198
/// happens, the [onChanged] callback will be invoked. To stop this callback
199
199
/// from being called after the painter has been discarded, call [dispose] .
200
200
abstract class BoxPainter {
201
- /// Abstract const constructor. This constructor enables subclasses to provide
202
- /// const constructors so that they can be used in const expressions.
203
- const BoxPainter ([this .onChanged]);
201
+ /// Default abstract constructor for box painters.
202
+ BoxPainter ([this .onChanged]) {
203
+ // TODO(polina-c): stop duplicating code across disposables
204
+ // https://github.com/flutter/flutter/issues/137435
205
+ if (kFlutterMemoryAllocationsEnabled) {
206
+ FlutterMemoryAllocations .instance.dispatchObjectCreated (
207
+ library: 'package:flutter/painting.dart' ,
208
+ className: '$BoxPainter ' ,
209
+ object: this ,
210
+ );
211
+ }
212
+ }
204
213
205
214
/// Paints the [Decoration] for which this object was created on the
206
215
/// given canvas using the given configuration.
@@ -243,5 +252,9 @@ abstract class BoxPainter {
243
252
/// The [onChanged] callback will not be invoked after this method has been
244
253
/// called.
245
254
@mustCallSuper
246
- void dispose () { }
255
+ void dispose () {
256
+ if (kFlutterMemoryAllocationsEnabled) {
257
+ FlutterMemoryAllocations .instance.dispatchObjectDisposed (object: this );
258
+ }
259
+ }
247
260
}
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import 'package:fake_async/fake_async.dart';
9
9
import 'package:flutter/foundation.dart' ;
10
10
import 'package:flutter/painting.dart' ;
11
11
import 'package:flutter_test/flutter_test.dart' ;
12
+ import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart' ;
12
13
13
14
import '../image_data.dart' ;
14
15
import '../painting/mocks_for_image_cache.dart' ;
@@ -813,4 +814,16 @@ void main() {
813
814
814
815
info.dispose ();
815
816
}, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87442
817
+
818
+ test ('$BoxPainter dispatches memory events' , () async {
819
+ await expectLater (
820
+ await memoryEvents (() => _BoxPainter ().dispose (), _BoxPainter ),
821
+ areCreateAndDispose,
822
+ );
823
+ });
824
+ }
825
+
826
+ class _BoxPainter extends BoxPainter {
827
+ @override
828
+ void paint (Canvas canvas, Offset offset, ImageConfiguration configuration) {}
816
829
}
You can’t perform that action at this time.
0 commit comments