prefer_shorthands_with_constructors
v0.3.0 Warning Fix Shorthand Patterns
Flags explicit constructor invocations of EdgeInsets, BorderRadius, Radius, and Border when the type can be inferred from context. In named arguments and collection literals, the class name is redundant and can be replaced with a dot shorthand like .all(), .symmetric(), or .circular().
Why use this rule
Section titled “Why use this rule”These Flutter classes appear frequently in widget trees, and their constructors are often passed as named arguments where the type is already known. Replacing EdgeInsets.all(8) with .all(8) reduces visual clutter in deeply nested build methods, making the widget tree easier to scan.
See also: Dart language - Constructor tear-offs
Padding( padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12), child: Text('Hello'),);
Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(18), border: Border.all(color: Colors.blue, width: 2), ),);
Padding(padding: EdgeInsets.all(8), child: Text('World'));Padding( padding: .symmetric(horizontal: 16, vertical: 12), child: Text('Hello'),);
Container( decoration: BoxDecoration( borderRadius: .circular(18), border: .all(color: Colors.blue, width: 2), ),);
Padding(padding: .all(8), child: Text('World'));Configuration
Section titled “Configuration”To disable this rule:
plugins: many_lints: diagnostics: prefer_shorthands_with_constructors: false