Re:Flutter 2
by okamiueru on Wednesday March 03, 2021 @04:14PM
(#26334639)
You could create an abstract class for the base response, then implement this abstract class for the two cases one where it has a list member, and one where it contains the object. Then, using the return value with something like `if (response is listLike) { }` the IDE already knows that you are scoped to having only the list like properties, and you'd get the full help of the language. Something like that, I suppose.
[ Parent
| on HN ]
Versus a sort of:
my_type = my_list | my_object
?
You can see why this is better :-)
Re:Flutter 2
by mixmastamyk on Thursday March 04, 2021 @12:31AM
(#26339007)
I'd always return a list. Makes the client code simpler.
You would. But not every input comes from you :-)