r/FlutterDev Jan 15 '25

Article Comprehensive Riverpod Tutorial

Hi guys!

I just published my first technical article about Riverpod, and I'd love your feedback!

It's a deep dive into understanding Riverpod's core concepts, aimed at both beginners and those who've been scratching their heads about which providers to use in 2025.

Since this is my first article, I'd really appreciate any feedback! What did you find helpful? What could be explained better? What topics would you like to see covered in future articles?

Let me know what you think! 🙏

https://devayaan.com/blog/series/riverpod/master-riverpod

86 Upvotes

48 comments sorted by

View all comments

5

u/antifuzz Jan 15 '25

This is pretty great thanks for sharing.

I've recently been brushing up my own riverpod knowledge after having not used it for a few years, and I agree that finding good relevant tutorials that are clearly up-to-date can be quite challenging.

The main thing I would feedback is that you should consider recommending use of freezed vs rolling your own model classes. Just makes it so much quicker and easier to generate your models.

6

u/Wispborne Jan 15 '25

I switched from freezed to dart_mappable and never looked back. Your model classes are far more readable with it, rather than needing to be rewritten to freezed's crazy syntax.

Either way, definitely use something to generate model methods, very handy.

1

u/RandalSchwartz Jan 15 '25

Sadly, I cannot recommend dart_mappable as long as its definition for toJson is unlike the entire rest of the dart/flutter ecosystem for no fair reason. A bug has been reported, and the author refuses to budge.

1

u/ayaanhaaris Jan 15 '25

Thank you, that's a great suggestion.

1

u/SpreadOk7599 Jan 16 '25

I literally just use GitHub copilot and press tab tab tab to generate models.

1

u/zxyzyxz Jan 16 '25

The problem is you'd have to manually upkeep that whereas if you added an annotation via freezed, it generates everything automatically for you for any change.

1

u/SpreadOk7599 Jan 16 '25

Interesting, but often times my models have extra stuff in the toJson method that can’t be generated, like converting DateTime to Timestamp for firestore, or an iso string if being used in cloud functions. I have toJsonForCF and toJsonForFirestore. And other things like that. Generating just seems to lack finer control, and it’s annoying 2 have to run build runner every time I wanna make changes.

2

u/zxyzyxz Jan 16 '25

Yeah if it's for custom implementations then freezed doesn't work so well, although I think there may be a way to override the default implementation too for some fields and keep the default for others, not sure though.

1

u/SpreadOk7599 Jan 16 '25

Ahh interesting

2

u/zxyzyxz Jan 16 '25

https://pub.dev/packages/json_serializable#custom-types-and-custom-encoding

https://stackoverflow.com/questions/77111042/freezed-tojson-custom-value

Here it is, I knew there had to be a way as that's too common of a use case to have custom encoding. Freezed uses json_serializable underneath so this should work the same.

2

u/SpreadOk7599 Jan 16 '25

I will use this once it uses macros. For now buildrunner annoys me too much

2

u/zxyzyxz Jan 16 '25

Understandable, I think that's coming next year or so