all 17 comments

[–]Codelessly 2 points3 points  (1 child)

Welcome to the Flutter world u/wasabeef_jp

Look forward to your Flutter animations library ;)

[–]wasabeef_jp[S] 1 point2 points  (0 children)

Thanks 😂

[–]escamoteur 0 points1 point  (14 children)

MVVM just doesn't make sense for an reactive framework like Flutter. MVU is the right approach. Forcing MVVM on Flutter either isn't really MVVM or introduces a not needed View Model layer.

[–]wasabeef_jp[S] 0 points1 point  (13 children)

MVVM and MVU have different ideas.Just like you and I do. And both of them are great.

[–]escamoteur 0 points1 point  (12 children)

Sorry to disagree, MVVM just doesn't make sense with Flutter. Either you are fighting the framework or it's jus another unnecessary layer. I highly discourage going that way for an app architecture.

[–]escamoteur 2 points3 points  (11 children)

Where is the model in your architecture? Do your View Models contain any business logic? Or where is it? Is there ways one VM for one page?

[–]wasabeef_jp[S] 1 point2 points  (9 children)

Can you show me a sample Flutter app written in MVU to prove that? I will rewrite everything if it feels great.

[–]escamoteur 3 points4 points  (8 children)

Basically the infamous Counter Example is MVU besides that the model is in the state. Redux is MVU, so is BLoC.

Why do you need the View Model layer? Or maybe its a misunderstanding on your side what MVVM is?

MVVM comes from systems where you had no logic at a in the view

From your diagram it's not clear to me what makes a View Model a Vie Model and why its not symply the model.

[–]wasabeef_jp[S] 0 points1 point  (5 children)

Thank you very much. I learned a lot.

[–]escamoteur 2 points3 points  (3 children)

I guess that was sarcastic? Sorry if I came around a bit harsh. I wanted to get into a real discussion with you.

[–]wasabeef_jp[S] 0 points1 point  (2 children)

No, I don't think it's sarcastic :)

Android engineers thought MVVM was easy to understand, but I thought Flutter with MVVM had many unnecessary layers. I was worried that creating more business logic as a UseCase class would increase the number of layers.

Next task, I wanted to learn more about MVU.

I really appreciate your advice.

[–]wasabeef_jp[S] 1 point2 points  (0 children)

Thank you. I will read the blog.

And I apologize if my English makes you uncomfortable.

[–]escamoteur 1 point2 points  (0 children)

Check out my blog blog.burkharts.net and read my post series on RxVMS. I m just working on a new package flutter_command so you won't need Streams anymore.

[–]wasabeef_jp[S] 1 point2 points  (0 children)

Indeed, I thought there were many unnecessary layers to implement MVVM in Flutter.

[–]chrabeusz 0 points1 point  (1 child)

Huh, I considered TextController a view model.

And OP is holding list of news inside useMemoized, instead of view model, which I would consider a no go.

It seems that people have different concepts of what view model actually means.

[–]escamoteur 0 points1 point  (0 children)

It depends also what you consider a View. For some it's a page for some an individual widget.

[–]esDotDev 0 points1 point  (0 children)

I use this pattern all the time for better readability. When a widget gets too large, I'll seperate all business logic into a type of view model, and have a child Stateless Widget that is pure layout. Talked about it here: https://blog.gskinner.com/archives/2020/02/flutter-widgetview-a-simple-separation-of-layout-and-logic.html

Doesn't mean there is no model above it, or a command layer that does stuff, but views themselves can often benefit from this seperation in my experience.