brianegan / new_flutter_template

Test ideas for a new flutter template
140 stars 23 forks source link

What Architecture should the app employ? #2

Open brianegan opened 3 years ago

brianegan commented 3 years ago

Beginner/Intermediate Flutter developers have asked for concrete guidance on how to structure Flutter apps. What kind of structure should the new template demonstrate?

Note: Most popular Flutter libraries separate Data Logic from Widgets, with some kind of object that connects them together. For the purposes of this question, we'll refer to this structure as MVC: Model (Data), View (Flutter Widgets), Controller (Object that connects Model to View). If you disagree with the naming, please visit the naming discussion

irvine5k commented 3 years ago

ChangeNotifier will be easier for beginners and intermediates. Other approaches use immutability that is very good but can be tricky for newcomers.

orestesgaolin commented 3 years ago

I'd lean towards MVC with either ChangeNotifier or ValueNotifier. This seems as a nice balance between complexity and possibilities. If the app is to be simple (e.g. single model), I'd prefer to have basic ValueNotifier (like user_list_controller in the example).

In professional practice it would be of course more common to use bloc, provider or any other tool, so maybe it's useful to guide newcomers to some Flutter docs page like this for more information?

chimon2000 commented 3 years ago

If we are going by the officially Flutter example, then ChangeNotifier/ValueNotifier + Provider since we can expect that a new developer will probably read that documentation.

That said, I generally love options 😄.

RobertBrunhage commented 3 years ago

I have been trying out a lot of different ones but I generally agree with @orestesgaolin here.

Personally I never use ChangeNotifiers as they could have quite a lot of side effects if you are not aware that values need to only have getters and lists are extremely common to make a mistake with. And probably the most commen questions I get is "why doesn't my UI update when I change X value". To me a ValueNotifier reduces the risk of this.

brianegan commented 3 years ago

Thanks so much @RobertBrunhage -- I know your content reaches a lot of folks in our "Beginner-to-intermediate" target audience. Really appreciate your perspective.

Marco87Developer commented 3 years ago

My very personal idea is that the architecture of a template should not depend on the level of the target audience. What I think needs to change is the way it is shown. Shown in small steps, even an advanced state management becomes easy to learn. And so, when the user has become an expert, he can easily use the same State Management even for complex projects.

Personally I would very much like the State Management used to be riverpod with StateNotifier and hooks.

asidt commented 3 years ago

After long pondering and evaluating, I personally decided to use an MVC / MVVM architecture which is inspired by Android's Architecture Components, so I guess the closer to it would be the MVC with ChangeNotifiers as Controllers. I think they're the best compromise between simplicity and scalability. I wouldn't go for the no arch, because people need references, especially well written references, and also I wouldn't go for Bloc/Cubit or Mobx .

SushantChandla commented 3 years ago

MVC with bloc from scratch with stream controllers or rxdart.

brianegan commented 3 years ago

My very personal idea is that the architecture of a template should not depend on the level of the target audience. What I think needs to change is the way it is shown. Shown in small steps, even an advanced state management becomes easy to learn.

Thanks so much for the feedback! What would you think of a fairly simple MVC-ish setup in place as a starting point, with a bit of code comments detailing the structure, and Code labs or other tutorials that demonstrate how to extend the template in a healthy way to add new features?

Or does that still feel like too much?

Marco87Developer commented 3 years ago

Thanks so much for the feedback! What would you think of a fairly simple MVC-ish setup in place as a starting point, with a bit of code comments detailing the structure, and Code labs or other tutorials that demonstrate how to extend the template in a healthy way to add new features?

Or does that still feel like too much?

I think it’s a good idea! What I think is important is to give the user a step-by-step guide from the simple to the more complex structure.

ghost commented 3 years ago

I would consider, if possible, 2 options in parallel:

  1. A vanilla application:

One that doesn't scare away new coders, focusing on easing the learning curve for these users.

  1. And something scalable, with great testability features:

For this second version, I would consider something like the swift-composable-architecture.

It's an Elm/Redux like architecture. It's fully open source under the MIT license. Here's a Tour of the Composable Architecture in 4 videos.

For a quick peak, their README has both a Basic Usage and Testing examples. As well as a very good amount of examples and case studies.

mjablecnik commented 3 years ago

I prefer using MVC architecture with GetX which is pretty simple for every beginner or intermediate user and extremely powerful for creating any nice application.

brianegan commented 3 years ago

Thanks for the additional feedback over the weekend, everyone :)

valle-xyz commented 3 years ago

I would also like to see a "professional" architecture, as this might rather serve as a template for a new project than a learning example.