auto_strings 1.0.1 copy "auto_strings: ^1.0.1" to clipboard
auto_strings: ^1.0.1 copied to clipboard

A simple Dart/Flutter code generator that converts plain text into static const String fields.

Auto Strings #

A lightweight Dart tool that automatically generates static const String constants from plain text lines β€” so you never have to write repetitive key–value strings again.

Pub Version License: MIT

πŸ’‘ Why I Created This #

In most Flutter apps, we keep a constants file to store all the strings used across the app β€” things like labels, error messages, and button texts. But writing these constants manually means:

  • Typing both the key and the value for every string
  • Repeating the same text in different places
  • Spending unnecessary time on boilerplate

For example:

class AppStrings{

static const String pleaseEnterFirstName = "Please enter first name.";
static const String pleaseEnterLastName = "Please enter last name.";

}

This is tedious and error-prone, especially in large apps.

Auto Strings solves this by letting you:

  1. Write only the values in a simple .txt file
  2. Automatically generate Dart constants with proper naming conventions
  3. Maintain a single source of truth for all your app’s strings

πŸš€ Features #

  • Automatic constant generation from plain text
  • Consistent naming using camelCase
  • Zero manual duplication between keys and values
  • Simple CLI command β€” no Flutter boilerplate required

πŸ“‚ Folder & File Structure #

auto_strings/
β”‚
β”œβ”€β”€ CHANGELOG.md
β”œβ”€β”€ LICENSE
β”œβ”€β”€ README.md
β”œβ”€β”€ analysis_options.yaml
β”œβ”€β”€ pubspec.yaml
β”‚
β”œβ”€β”€ bin/
β”‚   └── auto_strings.dart       # CLI entry point
β”‚
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ auto_strings.dart       # Package entry
β”‚   └── src/
β”‚       └── generator.dart      # Core generation logic
β”‚
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ auto_strings_test.dart  # Unit tests
β”‚   β”œβ”€β”€ output.dart             # Generated sample output
β”‚   └── strings.txt             # Sample input strings

πŸ“¦ Installation #

Add this to your pubspec.yaml:

dev_dependencies:
  auto_strings: ^1.0.0

πŸ› οΈ Usage #

1️⃣ Create your text file in assets folder (e.g. strings.txt):

Please enter first name.
Please enter last name.
Email is required.

2️⃣ Run the generator: In Terminal write below command

dart run auto_strings --input strings.txt --output lib/app_strings.dart

Command Explaination

dart run <package_name> --input <path_to_input_file> --output <path_to_output_file>

Breaking it down:

  1. dart run – Runs a Dart program or package.
  2. auto_strings – The name of your package’s CLI tool.
  3. --input strings.txt – A named argument telling the program which text file to read.
    • strings.txt is your source file containing plain text strings.
  4. --output lib/app_strings.dart – A named argument telling the program where to save the generated Dart file.
    • lib/app_strings.dart is the file that will be created (or overwritten) with the constants.
  • Example in words: β€œRun the auto_strings package, read strings from strings.txt, and generate a Dart constants file at lib/app_strings.dart.”

3️⃣ Generated output:

class AppStrings {
  static const String pleaseEnterFirstName = "Please enter first name.";
  static const String pleaseEnterLastName = "Please enter last name.";
  static const String emailIsRequired = "Email is required.";
}

πŸ§ͺ Running Tests

dart test

The included tests verify:

  • Correct file generation
  • Proper conversion from plain text to constants
  • Accurate camelCase naming

πŸ“œ License #

This package is licensed under the MIT License. You are free to use, modify, and distribute it β€” but please give credit.

❀️ Contributing #

Contributions, issues, and feature requests are welcome! If you’d like to improve Auto Strings, feel free to:

  • Fork the repo
  • Make your changes
  • Submit a pull request

Author #

Created & maintained by Hitesh Meghwal

  • Portfolio
  • LinkedIn
  • Blog
  • Threads
2
likes
0
points
12
downloads

Publisher

unverified uploader

Weekly Downloads

A simple Dart/Flutter code generator that converts plain text into static const String fields.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, path

More

Packages that depend on auto_strings