flutter-statenotifier-riverpod-tutorial icon indicating copy to clipboard operation
flutter-statenotifier-riverpod-tutorial copied to clipboard

The getter 'state' isn't defined for the class 'StateNotifierProvider' for newer Riverpod versions

Open iotanbo opened this issue 4 years ago • 5 comments

First of all, thanks for the excellent tutorial! It works fine as is, but after updating to flutter_riverpod: ^0.14.0+1 the following errors appear:

ERROR: lib/presentation/weather_search_page.dart:23:45: Error: The getter 'state' isn't defined for the class 'StateNotifierProvider<WeatherNotifier, dynamic>'

ERROR: lib/presentation/weather_search_page.dart:37:59: Error: The getter 'state' isn't defined for the class 'StateNotifierProvider<WeatherNotifier, dynamic>'

Because this is a tutorial follow by many, I believe it's important to check whether it is a minor syntax change or something more profound.

iotanbo avatar Apr 20 '21 14:04 iotanbo

Indeed, syntax of StateNotifierProvider has changed in version 0.14 as could be seen in the official repo: https://github.com/rrousselGit/river_pod/blob/master/examples/todos/lib/main.dart.

final todos = ref.watch(todoListProvider);
context.read(todoListProvider.notifier).add(value);

But the documenatation of the Riverpod package is not yet updated.

iotanbo avatar Apr 21 '21 09:04 iotanbo

Actually, here is a migration guide: https://riverpod.dev/docs/migration/0.13.0_to_0.14.0

iotanbo avatar Apr 21 '21 10:04 iotanbo

Anyone interested in the working project with riverpod version 0.14.0+3 please see this commit on my fork of this repo https://github.com/daniil-shumko/flutter-statenotifier-riverpod-tutorial/commit/6a6f7000eb2c4cb778fc2e7b8337815f0716607c

daniil-shumko avatar May 27 '21 19:05 daniil-shumko

@daniil-shumko maybe you could create a PR?

aboutandre avatar Jul 06 '21 10:07 aboutandre

@aboutandre only if @ResoDev is happy with the changes. He will also probably will have to update his video/blog post for this so that the code matches.

daniil-shumko avatar Jul 17 '21 22:07 daniil-shumko