Skip to content

bug: Options provided through pubspec.yaml:dart_define options are not case sensitive (enough). #15

@anandkkpr

Description

@anandkkpr

Description

Current Behaviour

When we set the class_name option for dart_define in pubspec.yaml, the generated class name output does not respect appropriate Flutter Class Name case - which is UpperCamelCase/PascalCase.

For example, if I specify that class_name should be EnvironmentVariables, then the output Class name should, indeed, be exactly that - class EnvironmentVariables {...}. Instead, only the first letter in the Class name is capitalised, all following characters are lower case.

Additionally, though the documentation does not mention this, I tested setting the class_name to "Snake Case" (words separated by _ "underscore" characters) and doing this causes the tool to generate the correct Class Name. E.g.:

dart_define:
  class_name: Environment_Variables

generates:

class EnvironmentVariables {
  // SNIP!...
}

Expected Behaviour

If we set class_name in pubspec.yaml:define_dart.class_name to a PascalCase string, the case should be retained and be output as the actual Class name in the generated *.gen.dart file. E.g.:

dart_define:
  class_name: EnvironmentVariables

should cause a Class named exactly that way to be generated in the appropriate file:

class EnvironmentVariables {
  // SNIP!...
}

Steps to reproduce

  1. Install dart_define as a dependency.
  2. Following the Dart Define package's documentation, use the information provided in the "Current Behaviour" section above to setup your pubspec.yaml file.
  3. For this example, because I'm using "Flavors", ensure you have a flavors:... section defined as specified in the usage instructions for dart_define.
  4. Assuming that you have a "Flavor" called "local", run dart run dart_define generate --FLAVOR=local.
  5. The generated *.gen.dart file (as specified by the dart_path option as specified by dart_define usage instructions) will have a Class name who's name only has its first letter capitalised.

Free word

Suggestion

Maybe, to save on time, simply update the README / usage instructions to mention that it's necessary to specify the class_name option in snake_case in order for it to be output in the correct PascalCase format.

Additionally: It's important to note that the documentation should also be updated to specify that variable[{name}] values should ALSO be specified with snake_case because camelCase for these is also not respected at present.

Example

dart_define:
  variables:
    - name: someVar

results in:

static const somevar = // SNIP!...

and

dart_define:
  variables:
    - name: SOME_VAR

results in:

static const someVar = // SNIP!...

Platform

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions