auto_strings 1.0.1
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.
π‘ 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:
- Write only the values in a simple .txt file
- Automatically generate Dart constants with proper naming conventions
- 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:
- dart run β Runs a Dart program or package.
- auto_strings β The name of your packageβs CLI tool.
- --input strings.txt β A named argument telling the program which text file to read.
- strings.txt is your source file containing plain text strings.
- --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