Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Updates for Flutter 3.16.0/Dart 3.2 #65

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
20 changes: 18 additions & 2 deletions lib/src/mock_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class _MockMaterialPageRoute extends MaterialPageRoute<void> {

void hackOverlays() {
for (var i = 0; i < overlayEntries.length; i++) {
final state = OverlayState();
// Entry can only be inserted when the state is mounted
final state = _MockOverlayState().._mounted = true;
final entry = OverlayEntry(builder: (_) => const SizedBox());
try {
// We need to call insert since that is the only way to populate the
Expand All @@ -17,11 +18,21 @@ class _MockMaterialPageRoute extends MaterialPageRoute<void> {
// so we just ignore the error and the hack will do its job.
state.insert(entry);
} catch (_) {}
// Set mounted back to false to make sure the state doesn't get
// marked as dirty during OverlayEntry.remove().
state._mounted = false;
overlayEntries[i] = entry;
}
}
}

class _MockOverlayState extends OverlayState {
late bool _mounted;

@override
bool get mounted => _mounted;
}

class _FakeRoute<T> extends Fake implements Route<T> {}

/// {@template mock_navigator_provider}
Expand Down Expand Up @@ -67,13 +78,18 @@ class MockNavigator extends Mock
with _MockNavigatorDiagnosticsMixin
implements NavigatorState {
/// {@macro mock_navigator}
MockNavigator() {
///
/// [canPop()] is automatically stubbed to return the value of
/// [initialCanPop].
MockNavigator({bool initialCanPop = false}) {
registerFallbackValue(_FakeRoute<dynamic>());
registerFallbackValue(_FakeRoute<Object>());
registerFallbackValue(_FakeRoute<void>());
registerFallbackValue(_FakeRoute<bool>());
registerFallbackValue(_FakeRoute<String>());
registerFallbackValue(_FakeRoute<num>());

when(canPop).thenReturn(initialCanPop);
alestiago marked this conversation as resolved.
Show resolved Hide resolved
}

final _routes = <_MockMaterialPageRoute>[];
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage: https://github.com/VeryGoodOpenSource/mockingjay

environment:
sdk: ">=2.18.0 <4.0.0"
flutter: ">=3.7.3"
flutter: ">=3.16.0"

dependencies:
flutter:
Expand Down
2 changes: 2 additions & 0 deletions test/src/mock_navigator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ void main() {
),
);

// Called by NavigatorState.didChangeDependencies initially
verify(() => navigator.canPop()).called(1);
await tester.tap(find.byType(TextButton));
verify(() => navigator.canPop()).called(1);
});
Expand Down