0

Recently, Flutter Riverpod 2.0 was released. I'm not sure what has changed with Flutter Riverpod 2.0. I hope someone can explain these changes to me.

If anyone can tell me what the changes are, I'd really appreciate it. Thank you in advance!

My Car
  • 4,198
  • 5
  • 17
  • 50
  • 4
    Check out the [change log.](https://pub.dev/packages/riverpod/changelog#200) Also check out this article on [riverpod 2.](https://codewithandrea.com/articles/flutter-state-management-riverpod/?utm_source=Newsletter&utm_medium=email&utm_campaign=flutter-state-management-riverpod) – Vraj Shah Oct 08 '22 at 13:49
  • @VrajShah Can you answer this question and summarize what exactly has changed? – My Car Oct 08 '22 at 22:51
  • It all depends on which version of riverpod you were using before? – Ruble Oct 09 '22 at 06:16
  • @Ruble I was using the `2.0.0-dev.7` version of `flutter_riverpod`. The latest is version `2.0.2` of `flutter_riverpod`, which is Flutter Riverpod 2.0 – My Car Oct 09 '22 at 06:19

1 Answers1

1
  1. If you used to pass parameter ref.read, now you should pass parameter ref => removed typedef Reader (as I understand, related to complication of testing), for example:
final myClassProvider1 = Provider<MyClass>((ref) {
  return MyClass(ref);
});

// or using tear-off

final myClassProvider2 = Provider<MyClass>(MyClass.new);

class MyClass {
  MyClass(this.ref);

  [-] final Reader reader;
  [+] final Ref ref;
}

For a quick solution, you can create your own Reader. However, this is not recommended, BUT will work as a quick fix.

typedef Reader = T Function<T>(ProviderBase<T> provider);
  1. In the meantime, you can use overrideWithProvider instead overrideWithValue.

And check with riverpod/changelog. Also, you can wait for the official article from Remi Rousselet:

An article is in progress and will be linked here once available.

Ruble
  • 2,589
  • 3
  • 6
  • 29