invalid_ deprecated_ optional_ annotation
                  The annotation '@Deprecated.optional' can only be applied to optional parameters.
Description
#
                    The analyzer produces this diagnostic when the @Deprecated.optional
                    annotation is applied to a parameter that isn't an optional parameter. The
                    annotation must not be used on a parameter in a local function, an
                    anonymous function, a function-typed parameter, or a typedef. It is only
                    valid on optional parameters in a top-level function, a method, or a
                    constructor.
                  
Example
#The following code produces this diagnostic because the annotation is on a required parameter:
void f(@Deprecated.optional() int p) {}
                      
                      
                      
                    Common fixes
#Remove the annotation:
void f(int p) {}
                      
                      
                      
                    Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-11-4. View source or report an issue.