meta
limitation: useResult
not available in factory
constructors
#55962
Labels
analyzer-pkg-meta
Issues related to package:meta
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
P3
A lower priority bug or feature request
type-enhancement
A request for a change that isn't a bug
Can't seem to find any existing open/closed issue regarding this.
Currently facing a situation, roughly akin to:
Given a new instance, built using a factory - sometimes containing a great deal of inner parameters, passed to it - it is impossible to check whether the result is actually used. The slightly more practical (actual) use case for this involves passing a rather complex instance, built through a redirecting
const factory
into a Flutter'sBuildContext
for subsequent state propagation / widget tree update. Assigning it to a temporary variable beforehand, though necessary at times, is completely redundant in the rest of cases.The
@useResult
annotation would be nothing short of perfect for this. Yet it vehemently refuses to do its job, insisting thatThe annotation 'useResult' can only be used on fields, getters, methods, top-level functions, or top-level variables.
While ignoring that message makes it ignore all the uses of the resulting instance completely.Any way to patch this up?
A rather messy fix for this currently involves either prior redundant assignment, or an even more redundant
static
method declaration - reduplicating the whole factory constructor in whole merely for a chance to annotate it with@useResult
.Wouldn't mind doing this either, if it wasn't for the
freezed
's own reliance on factory constructors for its code generation.The text was updated successfully, but these errors were encountered: