SonarSource Rules
  • Products

    In-IDE

    Code Quality and Security in your IDE with SonarQube Ide

    IDE extension that lets you fix coding issues before they exist!

    Discover SonarQube for IDE

    SaaS

    Code Quality and Security in the cloud with SonarQube Cloud

    Setup is effortless and analysis is automatic for most languages

    Discover SonarQube Cloud

    Self-Hosted

    Code Quality and Security Self-Hosted with SonarQube Server

    Fast, accurate analysis; enterprise scalability

    Discover SonarQube Server
  • SecretsSecrets
  • ABAPABAP
  • AnsibleAnsible
  • ApexApex
  • AzureResourceManagerAzureResourceManager
  • CC
  • C#C#
  • C++C++
  • CloudFormationCloudFormation
  • COBOLCOBOL
  • CSSCSS
  • DartDart
  • DockerDocker
  • FlexFlex
  • GitHub ActionsGitHub Actions
  • GoGo
  • HTMLHTML
  • JavaJava
  • JavaScriptJavaScript
  • JSONJSON
  • JCLJCL
  • KotlinKotlin
  • KubernetesKubernetes
  • Objective CObjective C
  • PHPPHP
  • PL/IPL/I
  • PL/SQLPL/SQL
  • PythonPython
  • RPGRPG
  • RubyRuby
  • RustRust
  • ScalaScala
  • ShellShell
  • SwiftSwift
  • TerraformTerraform
  • TextText
  • TypeScriptTypeScript
  • T-SQLT-SQL
  • VB.NETVB.NET
  • VB6VB6
  • XMLXML
  • YAMLYAML
Dart

Dart static code analysis

Unique rules to find Bugs, Vulnerabilities, Security Hotspots, and Code Smells in your DART code

  • All rules 126
  • Vulnerability4
  • Bug15
  • Security Hotspot8
  • Code Smell99
Filtered: 13 rules found
convention
    Impact
      Clean code attribute
        1. "child" properties should be placed last in widget instantiation

           Code Smell
        2. "part of" directives should be used with strings

           Code Smell
        3. Triple slash should be used for documentation comments

           Code Smell
        4. Adjacent string concatenation should be preferred

           Code Smell
        5. Non-constant names should comply with a naming convention

           Code Smell
        6. Function declarations should be preferred over variables

           Code Smell
        7. Extension identifiers should comply with a naming convention

           Code Smell
        8. Local identifiers should not start with underscore

           Code Smell
        9. File names should comply with a naming convention

           Code Smell
        10. Package names should comply with a naming convention

           Code Smell
        11. Constant names should comply with a naming convention

           Code Smell
        12. Files should end with a newline

           Code Smell
        13. Class names should comply with a naming convention

           Code Smell

        "child" properties should be placed last in widget instantiation

        consistency - conventional
        maintainability
        Code Smell
        • convention

        Widgets that have constructors accepting children widgets as named parameters, should be called with children arguments as the last ones.

        Why is this an issue?

        How can I fix it?

        More Info

        Flutter widgets may or may not have children. For example:

        • a Container widget can have a single child (in a property named child), or none at all
        • a OverflowBar widget can have multiple children (in a property named children), or none at all

        When a widget has children, it is common to pass them as named parameters. When that is the case, it is a good practice to pass them as the last arguments in the constructor invocation.

        This makes the code more readable and easier to understand.

        Exceptions

        The rule does not apply in the case of widgets that define their children via positional parameters, since the order of the parameters is fixed by the constructor signature:

        class MyWidget extends StatelessWidget {
          final Widget child;
          MyWidget(this.child, {Key? key}) : super(key: key);
        }
        
        var myWidget = MyWidget(MyChildWidget(), key: Key('myKey')); // Non applicable
        

        What is the potential impact?

        The child and children properties of widgets wrapping other widgets are usually the longest and most complex ones. If those are not placed last, vertical scrolling may hide the rest of the constructor invocation, that potentially include other properties modifying the behavior of the widget.

        For example, a Container may be introduced with the intent of applying a transformation, such as a rotation, that can crucially impact the overall UI layout.

        If the transformation property comes after the child widget, and the child widget is long and complex, the developer may miss the transformation property when inspecting the code.

        Container(
          // ...
          child: MyWidget(
            // very long widget definition
          ),
          // ...
          transformation: Matrix4.rotationZ(0.1), // This may be overlooked
        )
        

        The impact may be further amplified in the case of nesting of widgets within widgets within widgets:

        Container(
          child: MyWidget(
            // very long widget definition
            child: AnotherWidget(
              // very long widget definition
              child: YetAnotherWidget(
                // very long widget definition
              ),
              customProperty: 42, // This may be overlooked
            ),
            customProperty: 42, // This may also be overlooked
          ),
          transformation: Matrix4.rotationZ(0.1), // This may also be overlooked
        )
        
          Available In:
        • SonarQube CloudDetect issues in your GitHub, Azure DevOps Services, Bitbucket Cloud, GitLab repositories
        • SonarQube ServerAnalyze code in your
          on-premise CI
          Developer Edition
          Available Since
          10.8

        © 2008-2025 SonarSource SA. All rights reserved.

        Privacy Policy | Cookie Policy | Terms of Use