auto_strings 1.0.2+2 copy "auto_strings: ^1.0.2+2" to clipboard
auto_strings: ^1.0.2+2 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.2+2

๐Ÿ› ๏ธ 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 strings.txt lib/app_strings.dart AppStrings

Command Explaination

dart run <package_name> <path_to_input_file> <path_to_output_file> <class_name>

Breaking it down:

  1. dart run โ€“ Runs a Dart program or package.
  2. auto_strings โ€“ The name of your packageโ€™s CLI tool.
  3. strings.txt โ€“ A named argument telling the program which text file to read. -It is your source file containing plain text strings.
  4. lib/app_strings.dart โ€“ A named argument telling the program where to save the generated Dart file. -It is the file that will be created (or overwritten) with the constants.
  5. Class name is optional if not provided then default AppStrings is set.
  • 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

โœ… Test Cases Coverage #

Category Example String Status
Basic cases Hello World โœ… Passed
Strings with punctuation Hey what you doing? โœ… Passed
Strings with quotes Hey I'm Hitesh, how are you / "Quoted text" โœ… Passed
Strings with numbers This is my phone number 123456 โœ… Passed
Strings with special chars Password@123#\$% โœ… Passed
Strings with escape-like sequences C:\Users\Hitesh / \n \t \\ โœ… Passed
Strings with multiple spaces Hello World โœ… Passed
Non-English / Unicode เคจเคฎเคธเฅเคคเฅ‡, ใ“ใ‚“ใซใกใฏ, ู…ุฑุญุจุง โœจ Upcoming
Emojis Hello ๐Ÿ‘‹๐Ÿ˜Š๐Ÿ”ฅ โœ… Passed

๐Ÿ“œ License #

This package is licensed under the MIT License. You are free to use, modify, and distribute it.

โค๏ธ 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

1
likes
150
points
11
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

Documentation

API reference

License

MIT (license)

Dependencies

flutter, path

More

Packages that depend on auto_strings