auto_strings 1.0.2+2
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.
๐ก 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.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:
- dart run โ Runs a Dart program or package.
- auto_strings โ The name of your packageโs CLI tool.
- strings.txt โ A named argument telling the program which text file to read. -It is your source file containing plain text strings.
- 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.
- 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