brianegan / flutter_architecture_samples

TodoMVC for Flutter
http://fluttersamples.com/
BSD 3-Clause "New" or "Revised" License
8.74k stars 1.71k forks source link

Comments on the Vanilla example #72

Open gggustafson opened 5 years ago

gggustafson commented 5 years ago

A couple of comments.

  1. The vanilla sample is too complex for a flutter/dart beginner. The discussion located at flutter_architecture_samples/example/vanilla/ is useful in explaining how flutter can implement inter-widget communications out of the box. However, IMHO it is extraordinarily complex. It has pieces scattered all over the directory structure. Is there a simpler example? Somewhere you wrote that for multiple state values, I might try a Map. Vanilla was the closest example I could find. The example at https://medium.com/@maksimrv/reactive-app-state-in-flutter-73f829bcf6a7 is fine for a single state value but offers no help with multiple values.

  2. The following code (from flutter_architecture_samples-master\example\vanilla\lib\models.dart) presumably (from its name) toggles the value of the complete member of each TodoEntry

  void toggleAll() {
    final allCompleted = this.allComplete;

    todos.forEach((todo) => todo.complete = !allCompleted);
  } 

Why is allCompleted invoked? Why doesn't the code read

todos.forEach((todo) => todo.complete = !todo.complete);

If that was not what was intended, then the method's name should changed or a /// comment added preceding the declaration.

Kudos: Thank you for your teaching efforts. It is fantastic work!

brianegan commented 5 years ago

Hey there -- yah, I should probably rename vanilla to prop_drilling since a couple other examples are actually using "Vanilla" Flutter as well. By "Prop Drilling," I mean explicitly passing data from a Parent to a Child via constructors.

  1. Overall, I actually agree with you :) These aren't meant to be "perfect" examples, but explorations of different strategies for sharing state, and "Prop Drilling" is sort of the most basic technique for sharing data between Widgets. You just simply pass some data from one Widget to another. Overall, it makes some things very clear (Data gets passed explicitly down the tree, and you track exactly how it's passed), but it also makes some things more difficult! Ah, the classic computer science trade off.

  2. That logic is actually correct! If all Todos are complete, everything should be set to "Incomplete." If some todos are incomplete, everything should be set to "Complete." That said, maybe toggleAll isn't the best name. Any other suggestions?

Glad ya found these examples useful, and please let me know if ya disagree with this reasoning!

gggustafson commented 5 years ago
  1. I understand the problem. However, I find that most authors of flutter/dart documentation expect a certain level of experience that I only think exists in intermediate level flutter/dart developers. In your case, I realize that a set of libraries is required for all of your examples to avoid duplication. But localization is still something I'm not ready for.

  2. I have no suggestions for renaming the toggleAll function. I'm still not sure how it fits into the project.

  3. I have used your Vanilla code as an exemplar. But I cannot get an icon tap to trigger a rendering. Would you please look at my StackOverflow post (https://stackoverflow.com/questions/52523548/rendering-a-screen-on-icon-tap) and tell me what I am missing.

Thanks

cv692001 commented 4 years ago

Hey @mmcc007 I ma very new to open source contribution and I just want to start contribution can you please help me out to make this as my first contribution :)