Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/src/gestures/map_interactive_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ class MapInteractiveViewerState extends State<MapInteractiveViewer>
_keyboardListenerFocusNode.dispose();
}
_disposeKeyboardAnimations();
_isPanLeaping.dispose();
_isZoomLeaping.dispose();
_isRotateLeaping.dispose();

super.dispose();
}
Expand Down
54 changes: 54 additions & 0 deletions test/gestures/map_interactive_viewer_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map/src/gestures/map_interactive_viewer.dart';
import 'package:flutter_test/flutter_test.dart';

Expand Down Expand Up @@ -46,4 +50,54 @@ void main() {
},
);
});

group('MapInteractiveViewerState.dispose', () {
Widget map() => const Directionality(
textDirection: TextDirection.ltr,
child: MediaQuery(
data: MediaQueryData(size: Size(800, 600)),
child: FlutterMap(children: []),
),
);

testWidgets('disposes every ValueNotifier<bool> it created',
(tester) async {
final created = <Object>{};
final disposed = <Object>{};
void onEvent(ObjectEvent event) {
if (event.object is! ValueNotifier<bool>) return;
(event is ObjectCreated ? created : disposed).add(event.object);
}

FlutterMemoryAllocations.instance.addListener(onEvent);
addTearDown(
() => FlutterMemoryAllocations.instance.removeListener(onEvent),
);

await tester.pumpWidget(map());
await tester.pumpWidget(const SizedBox.shrink());

expect(created, isNotEmpty);
expect(created.difference(disposed), isEmpty);
});

testWidgets('can be torn down while a keyboard leap is in progress',
(tester) async {
await tester.pumpWidget(map());
await tester.pump();

// A short press starts a leap, which writes the leaping notifiers from
// the animation's listener until the curve reaches its leap maximum.
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowUp);
await tester.pump(const Duration(milliseconds: 16));
await tester.pump(const Duration(milliseconds: 16));
await tester.sendKeyUpEvent(LogicalKeyboardKey.arrowUp);
await tester.pump(const Duration(milliseconds: 16));

await tester.pumpWidget(const SizedBox.shrink());
await tester.pump(const Duration(seconds: 1));

expect(tester.takeException(), isNull);
});
});
}