<p align="center">
<a href="https://pub.dev/packages/flutter_gen">
<img src="https://github.com/tien-px/pt_flutter_gen/raw/main/images/logo.png" width="480px"/>
</a>
</p>
[](https://pypi.org/project/flutter_gen/)
[](https://pypi.org/project/flutter_gen/)
[](#)
[](#)
The Flutter code generator for your assets, fonts, colors,… to **`increase your productivity`**.
Inspired by [FlutterGen](https://github.com/FlutterGen/flutter_gen).
## Installation
### Python
Window
```sh
$ https://www.python.org/downloads/
```
Mac OS
```sh
$ brew install python3
```
### FlutterGen
Works with MacOS and Windows.
Window
```sh
$ pip install flutter_gen
```
Mac OS
```sh
$ pip3 install flutter_gen
```
Update via command line:
```sh
$ pip3 install -U flutter_gen
```
## Usage
Run `flutter_gen` after the configuration [`pubspec.yaml`](https://dart.dev/tools/pub/pubspec).
```sh
$ flutter_gen -h
$ flutter_gen watch
```
## Android Studio Plugin
* [Install Plugin](https://github.com/tien-px/pt_flutter_gen/tree/main/intellji)
## Configuration file
[FlutterGen]() generates dart files based on the key **`flutter`** of [`pubspec.yaml`](https://dart.dev/tools/pub/pubspec).
Default configuration can be found [here](#default-configuration).
```yaml
# pubspec.yaml
# ...
flutter:
uses-material-design: true
assets:
- assets/images/
fonts:
- family: Raleway
fonts:
- asset: assets/fonts/Raleway-Regular.ttf
- asset: assets/fonts/Raleway-Italic.ttf
style: italic
```
## Available Parsers
### Assets
Just follow the doc [Adding assets and images#Specifying assets](https://flutter.dev/docs/development/ui/assets-and-images#specifying-assets) to specify assets, then [FlutterGen]() will generate related dart files.
No other specific configuration is required.
_Ignore duplicated._
```yaml
# pubspec.yaml
flutter:
assets:
- assets/images
```
These configurations will generate **`images.g.dart`** under the **`lib/generated/`** directory by default.
#### Usage Example
[FlutterGen]() generates [Image](https://api.flutter.dev/flutter/widgets/Image-class.html) class if the asset is Flutter supported image format.
Example results of `assets/images/chip.jpg`:
- **`Images.chip`** is an implementation of [`AssetImage class`](https://api.flutter.dev/flutter/painting/AssetImage-class.html).
- **`Images.chip.image(...)`** returns [`Image class`](https://api.flutter.dev/flutter/widgets/Image-class.html).
- **`Images.chip.path`** just returns the path string.
```dart
Widget build(BuildContext context) {
return Image(image: R.images.chip);
}
Widget build(BuildContext context) {
return R.images.chip.image(
width: 120,
height: 120,
fit: BoxFit.scaleDown,
);
Widget build(BuildContext context) {
// Images.chip.path = 'assets/images/chip3/chip3.jpg'
return Image.asset(R.images.chip.path);
}
```
If you are using SVG images with [flutter_svg](https://pub.dev/packages/flutter_svg) you can use as:
```dart
Widget build(BuildContext context) {
return R.images.paint.svg(
width: 120,
height: 120
);
}
```
<details><summary>Example of code generated by FlutterGen</summary>
<p>
```dart
/// DO NOT EDIT. This is code generated via flutter_gen
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';
const _assetsImagePath = 'assets/images';
class Images {
static AssetGenImage get chip => const AssetGenImage('$_assetsImagePath/chip.png');
static SvgGenImage get paint => const SvgGenImage('$_assetsImagePath/paint.svg');
}
class AssetGenImage extends AssetImage {
const AssetGenImage(String assetName) : super(assetName);
Image image({
Key? key,
ImageFrameBuilder? frameBuilder,
ImageLoadingBuilder? loadingBuilder,
ImageErrorWidgetBuilder? errorBuilder,
String? semanticLabel,
bool excludeFromSemantics = false,
double? width,
double? height,
Color? color,
BlendMode? colorBlendMode,
BoxFit? fit,
AlignmentGeometry alignment = Alignment.center,
ImageRepeat repeat = ImageRepeat.noRepeat,
Rect? centerSlice,
bool matchTextDirection = false,
bool gaplessPlayback = false,
bool isAntiAlias = false,
FilterQuality filterQuality = FilterQuality.low,
}) {
return Image(
key: key,
image: this,
frameBuilder: frameBuilder,
loadingBuilder: loadingBuilder,
errorBuilder: errorBuilder,
semanticLabel: semanticLabel,
excludeFromSemantics: excludeFromSemantics,
width: width,
height: height,
color: color,
colorBlendMode: colorBlendMode,
fit: fit,
alignment: alignment,
repeat: repeat,
centerSlice: centerSlice,
matchTextDirection: matchTextDirection,
gaplessPlayback: gaplessPlayback,
isAntiAlias: isAntiAlias,
filterQuality: filterQuality,
);
}
String get path => assetName;
}
class SvgGenImage {
const SvgGenImage(this._assetName);
final String _assetName;
SvgPicture svg({
Key? key,
bool matchTextDirection = false,
AssetBundle? bundle,
String? package,
double? width,
double? height,
BoxFit fit = BoxFit.contain,
AlignmentGeometry alignment = Alignment.center,
bool allowDrawingOutsideViewBox = false,
WidgetBuilder? placeholderBuilder,
Color? color,
BlendMode colorBlendMode = BlendMode.srcIn,
String? semanticsLabel,
bool excludeFromSemantics = false,
Clip clipBehavior = Clip.hardEdge,
}) {
return SvgPicture.asset(
_assetName,
key: key,
matchTextDirection: matchTextDirection,
bundle: bundle,
package: package,
width: width,
height: height,
fit: fit,
alignment: alignment,
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
placeholderBuilder: placeholderBuilder,
color: color,
colorBlendMode: colorBlendMode,
semanticsLabel: semanticsLabel,
excludeFromSemantics: excludeFromSemantics,
clipBehavior: clipBehavior,
);
}
String get path => _assetName;
}
```
</p>
</details>
### Fonts
Just follow the doc [Use a custom font](https://flutter.dev/docs/cookbook/design/fonts) to specify fonts, then [FlutterGen]() will generate related dart files.
No other specific configuration is required.
_Ignore duplicated._
```yaml
# pubspec.yaml
flutter:
fonts:
- family: Raleway
fonts:
- asset: assets/fonts/Raleway-Regular.ttf
- asset: assets/fonts/Raleway-Italic.ttf
style: italic
- family: RobotoMono
fonts:
- asset: assets/fonts/RobotoMono-Regular.ttf
- asset: assets/fonts/RobotoMono-Bold.ttf
weight: 700
```
These configurations will generate **`fonts.g.dart`** under the **`lib/generated/`** directory by default.
#### Usage Example
```dart
Text(
'Hi there, I\'m FlutterGen',
style: TextStyle(
fontFamily: R.fonts.robotoMono,
fontFamilyFallback: const [R.fonts.raleway],
),
```
<details><summary>Example of code generated by FlutterGen</summary>
<p>
```dart
/// DO NOT EDIT. This is code generated via flutter_gen
class FontFamily {
FontFamily._();
static const String raleway = 'Raleway';
static const String robotoMono = 'RobotoMono';
}
```
</p>
</details>
### Colors
[FlutterGen]() supports generating colors from [TXT](assets/color/colors.txt) format files.
_Ignore duplicated._
[FlutterGen]() can generate a [Color](https://api.flutter.dev/flutter/material/Colors-class.html) class based on the color `hex` value.
```txt
#F5CB84
#955E1C
```
These configurations will generate **`colors.g.dart`** under the **`lib/generated/`** directory by default.
#### Usage Example
```dart
Text(
'Hi there, I\'m FlutterGen',
style: TextStyle(
color: R.colors.hexF5CB84,
),
```
<details><summary>Example of code generated by FlutterGen</summary>
<p>
```dart
import 'package:flutter/material.dart';
class ColorName {
ColorName._();
static const Color hexF5CB84 = Color(0xFFF5CB84);
static const Color hex955E1C = Color(0xFF955E1C);
}
```
</p>
</details>
## Issues
Please file [FlutterGen]() specific issues, bugs, or feature requests in our [issue tracker](https://github.com/tien-px/flutter_gen/issues/new).
<!-- ## Generate
### 1. Generate image class:
```
$ flutter_gen gen image
```
<details>
<summary>📑 Example</summary>
```dart
const _assetsImagePath = 'assets/images';
class Images {
static const test = '$_assetsImagePath/test.png';
}
```
</details>
### 2. Generate localization class:
```
$ flutter_gen gen localization
```
<details>
<summary>📑 Example</summary>
```dart
class i18n {
static String get test => 'test'.tr();
}
```
</details>
### 3. Generate router class:
```
$ flutter_gen gen router
```
<details>
<summary>📑 Example</summary>
```dart
Future? toHome({int? id}) {}
Future? offAllHome({int? id}) {}
Future? offAndToHome({int? id}) {}
Future? offHome({int? id}) {}
Future? offUntilHome({int? id}) {}
```
</details>
### 4. Sync:
#### Run all generate command
```
$ flutter_gen sync
``` -->
Raw data
{
"_id": null,
"home_page": "https://github.com/tien-px/pt_flutter_tools",
"name": "flutter-gen",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": null,
"keywords": null,
"author": "Pham Xuan Tien",
"author_email": "tienpx.x.x@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/cb/22/fd2ec6231972918fe9976993b10e212bf0f651acc72b9943450cdc039159/flutter_gen-2.2.0.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <a href=\"https://pub.dev/packages/flutter_gen\">\n <img src=\"https://github.com/tien-px/pt_flutter_gen/raw/main/images/logo.png\" width=\"480px\"/>\n </a>\n</p>\n\n[](https://pypi.org/project/flutter_gen/)\n[](https://pypi.org/project/flutter_gen/)\n[](#)\n[](#)\n\nThe Flutter code generator for your assets, fonts, colors,\u2026 to **`increase your productivity`**.\n\nInspired by [FlutterGen](https://github.com/FlutterGen/flutter_gen).\n\n## Installation\n\n### Python\n\nWindow\n\n```sh\n$ https://www.python.org/downloads/\n```\n\nMac OS\n\n```sh\n$ brew install python3\n```\n\n### FlutterGen\n\nWorks with MacOS and Windows.\n\nWindow\n\n```sh\n$ pip install flutter_gen\n```\n\nMac OS\n```sh\n$ pip3 install flutter_gen\n```\n\nUpdate via command line:\n\n```sh\n$ pip3 install -U flutter_gen\n```\n\n## Usage\n\nRun `flutter_gen` after the configuration [`pubspec.yaml`](https://dart.dev/tools/pub/pubspec).\n\n```sh\n$ flutter_gen -h\n\n$ flutter_gen watch\n```\n\n## Android Studio Plugin\n\n* [Install Plugin](https://github.com/tien-px/pt_flutter_gen/tree/main/intellji)\n\n## Configuration file\n\n[FlutterGen]() generates dart files based on the key **`flutter`** of [`pubspec.yaml`](https://dart.dev/tools/pub/pubspec). \nDefault configuration can be found [here](#default-configuration). \n\n```yaml\n# pubspec.yaml\n# ...\nflutter:\n uses-material-design: true\n assets:\n - assets/images/\n\n fonts:\n - family: Raleway\n fonts:\n - asset: assets/fonts/Raleway-Regular.ttf\n - asset: assets/fonts/Raleway-Italic.ttf\n style: italic\n```\n\n## Available Parsers\n\n### Assets\n\nJust follow the doc [Adding assets and images#Specifying assets](https://flutter.dev/docs/development/ui/assets-and-images#specifying-assets) to specify assets, then [FlutterGen]() will generate related dart files. \nNo other specific configuration is required. \n_Ignore duplicated._\n\n```yaml\n# pubspec.yaml\nflutter:\n assets:\n - assets/images\n```\n\nThese configurations will generate **`images.g.dart`** under the **`lib/generated/`** directory by default.\n\n#### Usage Example\n\n[FlutterGen]() generates [Image](https://api.flutter.dev/flutter/widgets/Image-class.html) class if the asset is Flutter supported image format.\n\nExample results of `assets/images/chip.jpg`:\n\n- **`Images.chip`** is an implementation of [`AssetImage class`](https://api.flutter.dev/flutter/painting/AssetImage-class.html).\n- **`Images.chip.image(...)`** returns [`Image class`](https://api.flutter.dev/flutter/widgets/Image-class.html).\n- **`Images.chip.path`** just returns the path string.\n\n```dart\nWidget build(BuildContext context) {\n return Image(image: R.images.chip);\n}\n\nWidget build(BuildContext context) {\n return R.images.chip.image(\n width: 120,\n height: 120,\n fit: BoxFit.scaleDown,\n );\n\nWidget build(BuildContext context) {\n // Images.chip.path = 'assets/images/chip3/chip3.jpg'\n return Image.asset(R.images.chip.path);\n}\n\n```\n\nIf you are using SVG images with [flutter_svg](https://pub.dev/packages/flutter_svg) you can use as:\n\n```dart\nWidget build(BuildContext context) {\n return R.images.paint.svg(\n width: 120,\n height: 120\n );\n}\n```\n\n<details><summary>Example of code generated by FlutterGen</summary>\n<p>\n\n```dart\n/// DO NOT EDIT. This is code generated via flutter_gen\n\nimport 'package:flutter/widgets.dart';\nimport 'package:flutter_svg/flutter_svg.dart';\n\nconst _assetsImagePath = 'assets/images';\n\nclass Images {\n static AssetGenImage get chip => const AssetGenImage('$_assetsImagePath/chip.png');\n static SvgGenImage get paint => const SvgGenImage('$_assetsImagePath/paint.svg');\n}\n\nclass AssetGenImage extends AssetImage {\n const AssetGenImage(String assetName) : super(assetName);\n\n Image image({\n Key? key,\n ImageFrameBuilder? frameBuilder,\n ImageLoadingBuilder? loadingBuilder,\n ImageErrorWidgetBuilder? errorBuilder,\n String? semanticLabel,\n bool excludeFromSemantics = false,\n double? width,\n double? height,\n Color? color,\n BlendMode? colorBlendMode,\n BoxFit? fit,\n AlignmentGeometry alignment = Alignment.center,\n ImageRepeat repeat = ImageRepeat.noRepeat,\n Rect? centerSlice,\n bool matchTextDirection = false,\n bool gaplessPlayback = false,\n bool isAntiAlias = false,\n FilterQuality filterQuality = FilterQuality.low,\n }) {\n return Image(\n key: key,\n image: this,\n frameBuilder: frameBuilder,\n loadingBuilder: loadingBuilder,\n errorBuilder: errorBuilder,\n semanticLabel: semanticLabel,\n excludeFromSemantics: excludeFromSemantics,\n width: width,\n height: height,\n color: color,\n colorBlendMode: colorBlendMode,\n fit: fit,\n alignment: alignment,\n repeat: repeat,\n centerSlice: centerSlice,\n matchTextDirection: matchTextDirection,\n gaplessPlayback: gaplessPlayback,\n isAntiAlias: isAntiAlias,\n filterQuality: filterQuality,\n );\n }\n\n String get path => assetName;\n}\n\nclass SvgGenImage {\n const SvgGenImage(this._assetName);\n\n final String _assetName;\n\n SvgPicture svg({\n Key? key,\n bool matchTextDirection = false,\n AssetBundle? bundle,\n String? package,\n double? width,\n double? height,\n BoxFit fit = BoxFit.contain,\n AlignmentGeometry alignment = Alignment.center,\n bool allowDrawingOutsideViewBox = false,\n WidgetBuilder? placeholderBuilder,\n Color? color,\n BlendMode colorBlendMode = BlendMode.srcIn,\n String? semanticsLabel,\n bool excludeFromSemantics = false,\n Clip clipBehavior = Clip.hardEdge,\n }) {\n return SvgPicture.asset(\n _assetName,\n key: key,\n matchTextDirection: matchTextDirection,\n bundle: bundle,\n package: package,\n width: width,\n height: height,\n fit: fit,\n alignment: alignment,\n allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,\n placeholderBuilder: placeholderBuilder,\n color: color,\n colorBlendMode: colorBlendMode,\n semanticsLabel: semanticsLabel,\n excludeFromSemantics: excludeFromSemantics,\n clipBehavior: clipBehavior,\n );\n }\n\n String get path => _assetName;\n}\n```\n\n</p>\n</details>\n\n### Fonts\n\nJust follow the doc [Use a custom font](https://flutter.dev/docs/cookbook/design/fonts) to specify fonts, then [FlutterGen]() will generate related dart files. \nNo other specific configuration is required. \n_Ignore duplicated._\n\n```yaml\n# pubspec.yaml\nflutter:\n fonts:\n - family: Raleway\n fonts:\n - asset: assets/fonts/Raleway-Regular.ttf\n - asset: assets/fonts/Raleway-Italic.ttf\n style: italic\n - family: RobotoMono\n fonts:\n - asset: assets/fonts/RobotoMono-Regular.ttf\n - asset: assets/fonts/RobotoMono-Bold.ttf\n weight: 700\n```\n\nThese configurations will generate **`fonts.g.dart`** under the **`lib/generated/`** directory by default.\n\n#### Usage Example\n\n```dart\nText(\n 'Hi there, I\\'m FlutterGen',\n style: TextStyle(\n fontFamily: R.fonts.robotoMono,\n fontFamilyFallback: const [R.fonts.raleway],\n ),\n```\n\n<details><summary>Example of code generated by FlutterGen</summary>\n<p>\n\n```dart\n/// DO NOT EDIT. This is code generated via flutter_gen\n\nclass FontFamily {\n FontFamily._();\n\n static const String raleway = 'Raleway';\n static const String robotoMono = 'RobotoMono';\n}\n\n```\n\n</p>\n</details>\n\n### Colors\n\n[FlutterGen]() supports generating colors from [TXT](assets/color/colors.txt) format files. \n_Ignore duplicated._\n\n[FlutterGen]() can generate a [Color](https://api.flutter.dev/flutter/material/Colors-class.html) class based on the color `hex` value.\n\n```txt\n#F5CB84\n#955E1C\n```\n\nThese configurations will generate **`colors.g.dart`** under the **`lib/generated/`** directory by default.\n\n#### Usage Example\n\n```dart\nText(\n 'Hi there, I\\'m FlutterGen',\n style: TextStyle(\n color: R.colors.hexF5CB84,\n ),\n```\n\n<details><summary>Example of code generated by FlutterGen</summary>\n<p>\n\n```dart\nimport 'package:flutter/material.dart';\n\nclass ColorName {\n ColorName._();\n \n static const Color hexF5CB84 = Color(0xFFF5CB84);\n static const Color hex955E1C = Color(0xFF955E1C);\n}\n```\n\n</p>\n</details>\n\n## Issues\n\nPlease file [FlutterGen]() specific issues, bugs, or feature requests in our [issue tracker](https://github.com/tien-px/flutter_gen/issues/new).\n\n<!-- ## Generate\n### 1. Generate image class:\n```\n$ flutter_gen gen image\n```\n<details>\n<summary>\ud83d\udcd1 Example</summary>\n\n```dart\nconst _assetsImagePath = 'assets/images';\n\nclass Images {\n static const test = '$_assetsImagePath/test.png';\n}\n```\n</details>\n\n### 2. Generate localization class:\n```\n$ flutter_gen gen localization\n```\n<details>\n<summary>\ud83d\udcd1 Example</summary>\n\n```dart\nclass i18n {\n static String get test => 'test'.tr();\n}\n```\n</details>\n\n### 3. Generate router class:\n```\n$ flutter_gen gen router\n```\n<details>\n<summary>\ud83d\udcd1 Example</summary>\n\n```dart\nFuture? toHome({int? id}) {}\n\nFuture? offAllHome({int? id}) {}\n\nFuture? offAndToHome({int? id}) {}\n\nFuture? offHome({int? id}) {}\n\nFuture? offUntilHome({int? id}) {}\n```\n</details>\n\n### 4. Sync:\n#### Run all generate command\n```\n$ flutter_gen sync\n``` -->\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A code generator for Flutter",
"version": "2.2.0",
"project_urls": {
"Homepage": "https://github.com/tien-px/pt_flutter_tools"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c7c1abaa9d887b48364f69a4487550f4b7212920d03940b43fb75a83f0d34562",
"md5": "bb9ac639d2d0d5e420763854362389d8",
"sha256": "498920e8a3d36b31aa2e74c6edc467e428282688e0274721c54d2e395a9ca7b3"
},
"downloads": -1,
"filename": "flutter_gen-2.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "bb9ac639d2d0d5e420763854362389d8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 46445,
"upload_time": "2024-05-10T03:38:19",
"upload_time_iso_8601": "2024-05-10T03:38:19.183679Z",
"url": "https://files.pythonhosted.org/packages/c7/c1/abaa9d887b48364f69a4487550f4b7212920d03940b43fb75a83f0d34562/flutter_gen-2.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "cb22fd2ec6231972918fe9976993b10e212bf0f651acc72b9943450cdc039159",
"md5": "0de16ad319da6cbcf212fc43683d7250",
"sha256": "62738e95c7cbfcc9bcea0eebac1058bda53031219b3c600990feff7f0cc09cd0"
},
"downloads": -1,
"filename": "flutter_gen-2.2.0.tar.gz",
"has_sig": false,
"md5_digest": "0de16ad319da6cbcf212fc43683d7250",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 32486,
"upload_time": "2024-05-10T03:38:21",
"upload_time_iso_8601": "2024-05-10T03:38:21.525472Z",
"url": "https://files.pythonhosted.org/packages/cb/22/fd2ec6231972918fe9976993b10e212bf0f651acc72b9943450cdc039159/flutter_gen-2.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-10 03:38:21",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tien-px",
"github_project": "pt_flutter_tools",
"github_not_found": true,
"lcname": "flutter-gen"
}