I am writing a Flutter app in Dart on Android Studio and using Google Gemini to assist in coding.
I have reams of code in two dozen files and spend most days reworking code written by Gemini until it doesn't show any compile errors.
Yesterday 'we' wrote a simple AsyncNotifier, AsyncNotifierProvider pair to manage my Image Form.
Here is the stripped down code:
final imageFormProvider = AsyncNotifierProvider<ImageFormNotifier, Map<String, dynamic>>(
(ref) => ImageFormNotifier(),
);
class ImageFormNotifier extends AsyncNotifier<Map<String, dynamic>> {
@override
FutureOr<Map<String, dynamic>> build() {
return {
'imageFileName': '',
};
}
}
The compile error I am getting is on this line:
(ref) => ImageFormNotifier(),
The error is:
The argument type 'ImageFormNotifier Function(dynamic)' can't be assigned to the parameter type 'ImageFormNotifier Function()'.
Gemini and I have tried a half dozen variations of this code to no avail.
The final step was to create a barebones app, strip the code down and see if the same error occurs, and it does.
This appears to be the first AsyncNotifier/AsyncNotifierProvider pair in my app, others are Provider, StateProvider, FutureProvider, etc.
(One of the problems coding with an AI assist is the mixed contexts, the focus of the next weeks' recoding efforts).
Gemini now believes I have actually discovered a bug in the code and wants me to submit it to Riverpod devs for resolution. I thought I'd ask here if anyone has seen this issue before and found a resolution, cuz you guys are good!
You have the wrong signature for the AsyncNotifierProvider's constructor. You want something like ImageFormNotifier.new
, because the constructor of an AsyncNotifier takes no arguments. This is shown in numerous examples on https://riverpod.dev.