flutterriverpodriverpod-annotation

Problem with using annotation @riverpod in working with Riverpod


Im following offical documentation and while trying to use @riverpod annotation in my code im getting error: "Undefined class 'HelloWorldRef' "

I tried to create provider like in documentation:

@riverpod
String helloWorld(HelloWorldRef ref) {
  return 'Hello world';
}

Solution

  • You have first to ensure that you have all packages installed in your project.

    flutter pub add flutter_riverpod
    flutter pub add riverpod_annotation
    flutter pub add dev:riverpod_generator
    flutter pub add dev:build_runner
    flutter pub add dev:custom_lint
    flutter pub add dev:riverpod_lint
    

    now you can run the code-generator with flutter pub run build_runner watch