Follow best practice of ProxyProvider updating#298
Conversation
The addresses feedback from flutter#245. Instead of constructing a new `CartModel`, we merely update the `catalog` field. We no longer need a fancy constructor, and `CartModel._catalog` cannot be final any more.
| CartModel(catalog, previousCart), | ||
| create: (context) => CartModel(), | ||
| update: (context, catalog, cart) { | ||
| cart.catalog = catalog; |
There was a problem hiding this comment.
Nit but I'd use the .. operator instead of making a block
There was a problem hiding this comment.
To offer a counterpoint, in a sample that's aimed at beginners (like this one), we sometimes stretch out the syntax to maximize readability for new folks.
Entirely your call which way to go, though, Filip.
There was a problem hiding this comment.
Yes, I had the cascade operator there at first but went with the more verbose syntax for the reason @redbrogdon mentions. We're not teaching Dart niceties here, so I go with as "vanilla" syntax as possible, so as to decrease cognitive load on the beginner user.
There was a problem hiding this comment.
@filiph @redbrogdon Thanks a ton, As a beginner user it's very hard to understand these kind of syntax ..
vanilla syntax rocks:)
| CartModel(catalog, previousCart), | ||
| create: (context) => CartModel(), | ||
| update: (context, catalog, cart) { | ||
| cart.catalog = catalog; |
There was a problem hiding this comment.
To offer a counterpoint, in a sample that's aimed at beginners (like this one), we sometimes stretch out the syntax to maximize readability for new folks.
Entirely your call which way to go, though, Filip.
The addresses feedback from #245. Instead of constructing a new
CartModel, we merely update thecatalogfield.We no longer need a fancy constructor, and
CartModel._catalogcannot be final any more.This change also upgrades to
pkg:provider4.0.2, just to stay on top of things (it's was a no-op in the case of this sample).