-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Labels
Description
Describe the bug
When using a mock provider that extends $Notifier and implements a generated notifier class, accessing the .notifier property throws a "Null check operator used on a null value" error.
To Reproduce
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
part 'mock_provider_test.g.dart';
void main() {
test('Minimum sample code to describe the problem', () {
final container = ProviderContainer.test(
overrides: [sampleProvider.overrideWith(() => SampleNotifierMock())],
);
// Null check operator used on a null value
container.read(sampleProvider.notifier);
});
}
@riverpod
class SampleNotifier extends _$SampleNotifier {
@override
bool build() {
return false;
}
}
class SampleNotifierMock extends $Notifier<bool>
with Mock
implements SampleNotifier {}Expected behavior
The .notifier property should return the mock instance without throwing a null check error, allowing proper testing of notifier-based providers with mocks.
Environment:
- Flutter: 3.32.0
- flutter_riverpod: ^3.0.3
- riverpod_annotation: ^3.0.3
- mockito: ^5.5.0