fluttergen / flutter_gen Goto Github PK
View Code? Open in Web Editor NEWThe Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
Home Page: https://pub.dev/packages/flutter_gen
License: MIT License
The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
Home Page: https://pub.dev/packages/flutter_gen
License: MIT License
We have around 50 icons in our app and we would like to autogenerate a value getter that returns a list of all the assets in the class
class $AssetsIconsGen {
const $AssetsIconsGen();
/// File path: assets/icons/arrow_down.svg
SvgGenImage get arrowDown => const SvgGenImage('assets/icons/arrow_down.svg');
/// File path: assets/icons/arrow_left.svg
SvgGenImage get arrowLeft => const SvgGenImage('assets/icons/arrow_left.svg');
List<SvgGenImage> get svgAssets => [arrowDown, arrowLeft];
}
The reason is that we have an internal design component library app that displays all the icons together
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.tool-versions
dart 2.19.6
flutter 3.7.12
.github/workflows/build.yml
actions/checkout v3
wasabeef/import-asdf-tool-versions-action v1.0.1
subosito/flutter-action v2
dart-lang/setup-dart v1
codecov/codecov-action v3
.github/workflows/release.yml
actions/checkout v3
wasabeef/import-asdf-tool-versions-action v1.0.1
subosito/flutter-action v2
dart-lang/setup-dart v1
softprops/action-gh-release v1
actions/upload-artifact v3
actions/download-artifact v3
peter-evans/repository-dispatch v2
.node-version
node 19.4.0
package.json
husky 8.0.3
lint-staged ^13.1.0
node-actionlint ^1.2.2
prettier ^2.8.3
prettier-plugin-packagejson ^2.4.0
pnpm 8.4.0
packages/command/pubspec.yaml
flutter_gen_core 5.3.0
args >=2.0.0 <3.0.0
test >=1.16.0 <2.0.0
test_process >=2.0.0 <3.0.0
flutter_lints >=2.0.1 <3.0.0
packages/core/pubspec.yaml
path >=1.8.0 <2.0.0
yaml >=3.0.0 <4.0.0
mime >=1.0.0 <2.0.0
xml >=5.0.0 <7.0.0
dartx >=1.0.0 <2.0.0
color >=3.0.0 <4.0.0
collection >=1.15.0 <2.0.0
json_annotation >=4.4.0 <5.0.0
glob >=2.0.0 <3.0.0
dart_style >=2.0.0 <3.0.0
analyzer >=4.7.0 <6.0.0
args >=2.0.0 <3.0.0
pub_semver >=2.0.0 <3.0.0
source_span >=1.8.0 <2.0.0
test >=1.16.0 <2.0.0
flutter_lints >=2.0.1 <3.0.0
build_runner >=2.0.0 <3.0.0
json_serializable >=6.0.0 <7.0.0
version_gen >=1.0.1 <2.0.0
packages/runner/pubspec.yaml
flutter_gen_core 5.3.0
build >=2.0.0 <3.0.0
collection >=1.15.0 <2.0.0
crypto >=3.0.0 <4.0.0
glob >=2.0.0 <3.0.0
path >=1.8.0 <2.0.0
flutter_lints >=2.0.1 <3.0.0
build_test >=2.0.0 <3.0.0
pubspec.yaml
melos ^3.0.1
Setting flutter_gen as the output folder name, the generated folder name is always gen/
flutter_gen:
output: lib/flutter_gen/
Can you solve this? Thanks!
This package has the exact same name than the official flutter localization package, resulting in name collision.
After importing flutter_gen package (this package), my localization files are broken.
error: Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'.
Any ideas ?
EDIT
I just found that the file ".dart_tool\package_config.json" contains a ref to flutter_gen-1.2.1
{
"name": "flutter_gen",
"rootUri": "../../../../AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutter_gen-1.2.1",
"packageUri": "lib",
"languageVersion": "2.7"
},
And this package is currently at 1.2.1, so I guess the plugin used by Flutter is this one ? So it's the same package after all ?
But why it collides then ?
I have an app where I use flutter_gen for working with fonts and are no assets. It would be nice to not generate the empty Assets
class in such cases. At least parameters like generate_assets
, generate_fonts
with true at default in the yaml file will be great.
Is it possible to select only some folders and not all from assets/
?
with this I mean overriding the default
flutter:
assets:
- ...
and tell flutter_gen
to generate the assets only of some directories
Having a & in the name of the asset causes the build to fail.
line 222, column 27 of .: Unexpected text 'Crafts'.
╷
222 │ String get arts&Crafts => 'assets/images/superpowers/Arts & Crafts.svg';
│ ^^^^^^
╵
line 222, column 26 of .: Operator declarations must be preceded by the keyword 'operator'.
╷
222 │ String get arts&Crafts => 'assets/images/superpowers/Arts & Crafts.svg';
│ ^
╵
line 222, column 26 of .: Methods must have an explicit list of parameters.
╷
222 │ String get arts&Crafts => 'assets/images/superpowers/Arts & Crafts.svg';
│ ^
╵
line 222, column 26 of .: A function body must be provided.
╷
222 │ String get arts&Crafts => 'assets/images/superpowers/Arts & Crafts.svg';
│ ^
╵
I can't update freezed to 1.1.1
, because flutter_gen
depends on analyzer: '>=2.0.0 <3.0.0'
and freezed requires analyzer: ^3.0.0
Because no versions of flutter_gen_runner match >4.1.4 <5.0.0 and flutter_gen_runner 4.1.4 depends on flutter_gen_core ^4.1.4, flutter_gen_runner ^4.1.4 requires flutter_gen_core ^4.1.4.
Because flutter_gen_core 4.1.4 depends on analyzer ^2.0.0 and no versions of flutter_gen_core match >4.1.4 <5.0.0, flutter_gen_core ^4.1.4 requires analyzer ^2.0.0.
Thus, flutter_gen_runner ^4.1.4 requires analyzer ^2.0.0.
And because freezed >=1.1.1 depends on analyzer ^3.0.0, flutter_gen_runner ^4.1.4 is incompatible with freezed >=1.1.1.
So, because customer depends on both freezed ^1.1.1 and flutter_gen_runner ^4.1.4, version solving failed.
pub get failed (1; So, because customer depends on both freezed ^1.1.1 and flutter_gen_runner ^4.1.4, version solving failed.)
Please upgrade analyzer to ^3.0.0
Warning: Calling bottle :unneeded is deprecated! There is no replacement.
Please report this issue to the fluttergen/tap tap (not Homebrew/brew or Homebrew/core):
/usr/local/Homebrew/Library/Taps/fluttergen/homebrew-tap/Formula/fluttergen.rb:6
Same for me for file names like:
[email protected]
Originally posted by @elianmortega in #115 (comment)
Assuming that I have build_runner
and flutter_gen_runner
configured properly in my pubspec.yaml should these run with every build? Or is it only possible to build these manually using flutter packages pub run build_runner build
? Thanks.
Awesome package... I see you got flare support. You might also support .riv files.
I can't update freezed, because flutter_gen
depends on analyzer: ^1.0.0
and freezed requires analyzer: ^2.0.0
Because flutter_gen_core 3.1.1 depends on analyzer ^1.0.0 and no versions of flutter_gen_core match >3.1.1 <4.0.0, flutter_gen_core ^3.1.1 requires analyzer ^1.0.0.
And because freezed >=0.14.3 depends on analyzer ^2.0.0, freezed >=0.14.3 is incompatible with flutter_gen_core ^3.1.1.
And because flutter_gen_runner 3.1.1 depends on flutter_gen_core ^3.1.1 and no versions of flutter_gen_runner match >3.1.1 <4.0.0, freezed >=0.14.3 is incompatible with flutter_gen_runner ^3.1.1.
So, because network_health depends on both flutter_gen_runner ^3.1.1 and freezed ^0.14.5, version solving failed.
Please upgarde analyzer to ^2.0.0
Hey there!
Would be great to have integration for the lottie files (through https://pub.dev/packages/lottie). Right now in the project I'm working on we're using the syntax:
Lottie.asset(Assets.animations.animationName)
but would be lovely to achieve it just like for the SVG files through the generated code:
Assets.animations.animationName.lottie()
The trickiest part would be probably to distinguish lottie files from non-lottie files, as it uses .json
as the file extension?
Just came across this repo, very cool.
Something we do is store content in yaml files so they are easy to edit by non developers. It would be great to have everything type safe. It looks like yaml
is already a dependency for this package. Is it reasonable to add yaml files as a supported file type? One way to do it would be to convert the yaml to json first then put the resulting data into a yaml
namespace using the existing json converter.
Thanks!
Currently generated Assets like Assets.image.foo.bar
is not const.
Someone may prefer to use const Widget, so it's better to add an option to generate a const version.
Example: Assets.image_foo_bar
.
Hi,
Could you please add a config parameter to be able to use not default class name such as 'Asstes' but custom one?
So if custom class name is MyAssets
result should be:
MyAssets.images.aaa
MyAssets.fonts.aaa
On running the build runner command I am getting these errors.
My dev dependencies are:
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: ^2.1.4
flutter_gen_runner: ^4.0.0
lint: ^1.7.2
import_sorter: ^4.6.0
Flutter doctor result:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.19043.1288], locale en-IN)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.61.1)
Commands tried:
flutter clean
flutter pub get
flutter pub global activate flutter_gen
flutter pub run build_runner build --delete-conflicting-outputs
flutter pub global activate flutter_gen
Package flutter_gen is currently active at version 4.0.0.
Resolving dependencies...
The package flutter_gen is already activated at newest available version.
To recompile executables, first run `global deactivate flutter_gen`.
Installed executable fluttergen.
Activated flutter_gen 4.0.0.
Hey,
I created a project to test the library and whenever I'm importing a local library in my test project (either by having a reference to it or using the dependency_overrides method), I do have the following error.
The pubspec.yaml file has changed since the pubspec.lock file was generated, please run "pub get" again.
pub finished with exit code 65
Here is the how to reproduce this issue.
pubspec.yaml
with the relative path to the previously cloned folderbuild_runner
and flutter_gen
libsflutter pub get
and flutter pub run build_runner build --delete-conflicting-outputs
pubspec.yaml
version: 1.0.0+1
environment:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
font_awesome_flutter:
path: ../font_awesome_flutter/
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
# cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
build_runner:
flutter_gen:
And here is my flutter doctor -v
[✓] Flutter (Channel unknown, 2.0.3, on Mac OS X 10.15.6 19G2021 darwin-x64, locale en-FR)
• Flutter version 2.0.3 at /Users/florian/fvm/versions/2.0.3
• Framework revision 4d7946a68d (2 weeks ago), 2021-03-18 17:24:33 -0700
• Engine revision 3459eb2436
• Dart version 2.12.2
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
• Android SDK at /Users/florian/Library/Android/sdk/
• Platform android-30, build-tools 29.0.3
• ANDROID_HOME = /Users/florian/Library/Android/sdk/
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
✗ Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/macos#android-setup for more details.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.1, Build version 12A7403
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 44.0.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] IntelliJ IDEA Ultimate Edition (version 2019.1)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin version 191.6183.88
[✓] VS Code (version 1.43.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension can be installed from:
🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[✓] Connected device (2 available)
• macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.6 19G2021 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 89.0.4389.114
If I do the same thing but targeting the published package of font_awesome_flutter
instead of the local one, no problem.
I may have missed a crucial information !
Thank you
First of all, definitely loving this generator. ❤
But if I may be allowed to request for a feature, please add support for MaterialAccentColor. 🙏🥺
Thanks! 😄
Sometimes it happens that for compatibility I need to use .png and .svg file with the same name e.g. splash.svg
and splash.png
.
It would be awesome to automatically generate different field names for these files e.g. splash_svg
and splash_png
.
I got stuck if I have mentioned more than one color in colors.xml file it is not updating the colors.gen.dart. Works fine if there is only one color in the file
When I run "pub get" appears this error
Because flutter_gen >=2.0.1 <2.0.2 depends on flutter_gen_core ^2.0.1 and flutter_gen >=2.0.2 depends on flutter_gen_core ^2.0.2, flutter_gen >=2.0.1 requires flutter_gen_core ^2.0.1.
And because flutter_gen_core >=2.0.1-dev.0 depends on json_annotation ^3.1.0, flutter_gen >=2.0.1 requires json_annotation ^3.1.0.
So, because your_project depends on both json_annotation ^4.0.0 and flutter_gen ^2.0.1, version solving failed.
Can you please update the dependency?
You're welcome to send us a PR so more people can find your package
https://github.com/Solido/awesome-flutter
Thx !
Since current version of flutter_gen_runner 3.1.2 depends on analyzer 2.0.0 which depends on meta 1.7.0.
and current version of flutter stable is still constrained to meta 1.3.0
you probably need to override meta version until flutter stable is updated by adding the following to your pubspec file.
dependency_overrides:
meta: ^1.7.0
auto_route_library Issue #648 is the same.
By making AssetGenImage
callable, instead of writing Assets.images.profile.image()
we can write Assets.images.profile()
. Will be happy to create a PR on this:)
For example,
class $AssetsBlobLottieGen {
const $AssetsBlobLottieGen();
/// File path: assets/blob/lottie/bug.json
String get bug => 'assets/blob/lottie/bug.json';
}
can be
class $AssetsBlobLottieGen {
const $AssetsBlobLottieGen();
/// File path: assets/blob/lottie/bug.json
const bug = 'assets/blob/lottie/bug.json';
}
Similar holds for AssetGenImage and so on.
Then we can use that value as constant happily. For example,
child: Image(
image: Assets.icon.icon,
width: 64,
height: 64,
),
can be
child: const Image( // <-- notice "const"
image: Assets.icon.icon,
width: 64,
height: 64,
),
Hello! I'm missing the ability to specify a package for icons
I notice ".flr" file used by flare_flutter is not generated.
This package is widely used to add animation to flutter apps, just like lottie from Airbnb.
version 1.2.1 by dart command-line.
Thank you very much.😀
Hello! 👋
As a developer, I work on packages that need to contain assets. When that happens, those assets need to be referenced in a different way (see links below):
It'd be amazing for flutter_gen
to support this use case.
If you believe this is a valid use case, I'd be more than happy to take a look and come up with a proposal / pull request.
Thank you! 💯
I've tried to use json_serializable in the latest version 5.0.0 together with flutter_gen
, and after adding both to pubspec.yaml, I'm receiving following error:
Because flutter_gen_core 3.1.1 depends on analyzer ^1.0.0 and no versions of flutter_gen_core match >3.1.1 <4.0.0, flutter_gen_core ^3.1.1 requires analyzer ^1.0.0.
And because json_serializable 5.0.0 depends on analyzer ^2.0.0 and flutter_gen_runner 3.1.1 depends on flutter_gen_core ^3.1.1, json_serializable 5.0.0 is incompatible with flutter_gen_runner 3.1.1.
So, because app depends on both flutter_gen_runner 3.1.1 and json_serializable 5.0.0, version solving failed.
pub get failed (1; So, because app depends on both flutter_gen_runner 3.1.1 and json_serializable 5.0.0, version solving failed.)
I thought that this can be solved with a simple override of conflicting analyzer
dependency so I added this to my pubspec.yaml:
dependency_overrides:
analyzer: ^2.0.0 # Required by flutter_gen_core -> 1.0.0
After this, pub get
finishes without error, but any attempt to run flutter pub run build_runner build
ends up with null-safety errors (after flutter_gen
phase is finished) like this:
[SEVERE] json_serializable:json_serializable on lib/communication/network/model/login_response_dto.dart (cached):
Generator cannot target libraries that have not been migrated to null-safety.
package:app/communication/network/model/login_response_dto.dart:4:7
╷
4 │ class LoginResponseDTO {
│ ^^^^^^^^^^^^^^^^
╵
and
This builder requires Dart inputs without syntax errors.
However, package:app/presentation/screen/splash/splash_screen.dart (or an existing part) contains the following errors.
splash_screen.dart:9:26: This requires the 'non-nullable' language feature to be enabled.
Try fixing the errors and re-running the build.
I've tried to resolve this for a while now, but I fail to understand if this is caused by flutter_gen
or json_serializble
. Any suggestion on how to approach this?
Since the version constraints of dartx in pubspec.yaml of flutter_gen core is <1.0.0 and the current version of dartx is 1.0.0, pub get throws conflicts error
Because no versions of flutter_gen match >4.1.3 <5.0.0 and flutter_gen 4.1.3 depends on flutter_gen_core ^4.1.3, flutter_gen ^4.1.3 requires flutter_gen_core ^4.1.3.
Because flutter_gen_core 4.1.3 depends on dartx >=0.6.0 <1.0.0 and no versions of flutter_gen_core match >4.1.3 <5.0.0, flutter_gen_core ^4.1.3 requires dartx >=0.6.0 <1.0.0.
Thus, flutter_gen ^4.1.3 requires dartx >=0.6.0 <1.0.0.
So, because itorrentsearch depends on both dartx ^1.0.0 and flutter_gen ^4.1.3, version solving failed.
I have a problem when load asset generated in one module and it can be accessed in another module. i have read generated file but not found to set package for assetimage
currently i using path generated image and making AssetImage from the path.
AssetImages( Assets.image.widgets.textDialogBox.textDialogBoxImage.path, package: "myPackage")
I've tried running FlutterGen with any
version and ^2.0.0
version, but I still have conflict with intl_translation
Because flutter_gen_runner >=2.0.0 depends on flutter_gen_core ^2.0.0 which depends on dart_style ^1.3.12, flutter_gen_runner >=2.0.0 requires dart_style ^1.3.12.
Because dart_style >=1.3.13 requires SDK version >=2.11.99 <3.0.0 and dart_style >=1.3.11 <1.3.13 depends on analyzer ^0.41.1, dart_style >=1.3.11 requires analyzer ^0.41.1.
(1) Thus, flutter_gen_runner >=2.0.0 requires analyzer ^0.41.1.
Because intl_translation >=0.17.8 <=0.17.10 depends on analyzer >=0.36.0 <0.40.0 and no versions of intl_translation match >0.17.10+1 <0.18.0, intl_translation >=0.17.8 <0.17.10+1 or >0.17.10+1 <0.18.0 requires analyzer >=0.36.0 <0.40.0.
And because intl_translation 0.17.10+1 depends on analyzer ^0.39.12, intl_translation ^0.17.8 requires analyzer >=0.36.0 <0.40.0.
And because flutter_gen_runner >=2.0.0 requires analyzer ^0.41.1 (1), flutter_gen_runner >=2.0.0 is incompatible with intl_translation ^0.17.8.
So, because DemoProject depends on both intl_translation ^0.17.10 and flutter_gen_runner ^2.0.0, version solving failed.
Any idea how to make it work? Thank you!
Create the folders for:
- assets/images/1x/
- assets/images/2x/
- assets/images/3x/
Code for the assets in this folders are not generated.
Question: How does flutter gen handle images for different resolutions? This could be done automatically.
FlutterGen is wonderfull, but I do not know how to use it with Flame. Flame already assumes that images are in assets/images/
. When loading an image image.load('filename.png')
is used without the path. FlutterGen generates the whole path. I guess I could always remove assets/images/
from the string before using it, but it does not feel right. Flame also has assets/audio/
. Will there be support for audio, too, sometime in the future?
build.yaml intended for generators configuration.
So could be nice to use build.yaml configuration instead of pubspec.yaml configuration.
❌ Bad
pubspec.yaml
⭕️ Good
build.yaml
I've been generating the assets and got surprised by unexpected records. Well, its kinda expected (the file exists there), but would be great to ignore these, as I don't treat .DS_Store
as my project files :)
...
String get dSStore => 'animations/.DS_Store';
...
Any chance to expose exclude
config (similar to the one we have in analasis_options.yaml
) or at least ignore some well known files by default? <3
First of all, amazing tool! Use it on the daily!
Is there a way to tell the tool not to generate dart 2.12 optional fields?
Many of my projects are still on non null-sound libraries, it's quite tedious to go and delete all the ?
every time the tool runs
In the latest version application assets are pathed through a package directory that does not exists. This can be observed in the example project.
SvgPicture svg({
Key? key,
bool matchTextDirection = false,
AssetBundle? bundle,
String? package = 'example',
...
In this case the example package does not exist in the example project so the following excepion occurs.
======== Exception caught by image resource service ================================================
The following assertion was thrown resolving an image codec:
Unable to load asset: packages/example/assets/images/chip1.jpg
When the exception was thrown, this was the stack:
#0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:227:7)
<asynchronous suspension>
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:667:14)
<asynchronous suspension>
Image provider: AssetGenImage(bundle: null, name: "packages/example/assets/images/chip1.jpg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#732c2(), name: "packages/example/assets/images/chip1.jpg", scale: 1.0)
The only way to fix this is to manually set package to null in asset widget:
Assets.images.icons.fuchsia.svg(package: null)
Is there a way to blanket disable the package name in version 3.1.0 for all assets?
Please read this #49.
This package has exactly the same name as the official Flutter Localization package, so there is a name conflict. Therefore, the official L10n (Flutter 1.22 +) and build_runner of FlutterGen cannot be used at the same time.
*Dart CLI and Homebrew are fine.
We now have these options available.
Please vote...
Sometimes I have assets that are not on the list of supported extensions but I would still like to have strings generated for them. At the moment flutter_gen just ignores these files and generates no strings for them.
For the following snippet from pubspec.yaml
:
flutter:
assets:
- CHANGELOG.md
I would expect to have a string generated for CHANGLELOG.md
to avoid using hardcoded strings in my code to reference this asset.
Please consider the following use-case:
assets/images/... -> should be generated
assets/data/... -> should not be generated
All files inside the data folder are simple data files, for example json or xml files. Which are used internally in the flutter application and therefore should not be considered as layout files (images, color, fonts etc.).
It would be great to have an exclude:
property to defines those files or directories.
Originally posted by @jayjah in #132 (comment)
[SEVERE]
Could not format because the source could not be parsed:
line 105, column 25 of .: Methods must have an explicit list of parameters.
╷
105 │ AssetGenImage get 460 => const AssetGenImage('assets/images/placeholders/460.jpg');
A current workaround would be to rename all the files to e.g. p_460.jpg
For example I have the next settings:
# pubspec.yaml
flutter:
assets:
- assets/images/profile.jpg
And the library generates path to the profile image.
Widget build(BuildContext context) {
// Assets.images.profile.path = 'assets/images/profile.jpg'
return Image.asset(Assets.images.profile.path);
}
But sometime I need to write a specific code and have access to the folder assets/images
. Could you support the logic?
var imagesPath = Assets.images.path;
// do some magic in the folder
info: The import of 'package:flutter/services.dart' is unnecessary because all of the used elements are also provided by the import of 'package:flutter/widgets.dart'. (unnecessary_import at [app] lib/gen/assets.gen.dart:10)
When I run the generator against a project with sdk constraints set to a version with nullability on (>=2.12-0-0) I expect that the generated code is compatible with the null safety features. It is not at the moment.
I created a bash script workaround that will add the @dart=2.10
comment on top.
#!/bin/bash
fluttergen
sed -i '' '1 s/^/\/\/@dart=2.10\n/' lib/core/assets/assets.gen.dart
I currently don't have time to submit a PR with updated functionality, but if someone else is struggling with this, they can use the workaround until a compatible version is released.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.