Closed samithe7 closed 1 year ago
Hello @samithe7
you can try like this Assets.images.imagesChip1.path
thanks but i want make the widget const . if i use Assets.images.imagesChip1.path widget don;t be const .
We should consider adding an option to toggle this just like svg_intergation. Currently, how about making your widget path nullable:
class MyWidget extends StatlessWidget {
const MyWidget(this.path);
final String? path;
Widget build(BuildContenxt context) {
final effectivePath = path ?? 'default_path';
return ...;
}
}
This pattern is also common in flutter.
now i get assets.gen.dart file
static const AssetGenImage imagesChip1 =
AssetGenImage('assets/images/chip1.jpg');
Is there any way in assets.gen.dart file only get String like this
static const String imagesChip1 =
'assets/images/chip1.jpg';
@lcdsmao I think the main goal of @samithe7 (also me) is making the Image widget as const. How about providing an option to generate assets separately?
e.g) TO-BE
class AssetImages {
static const avatar = AssetGenImage('assets/images/avatar.png');
...
}
class AssetFonts{
...
}
AS-IS
class Assets {
Assets._();
static const $AssetsFontsGen fonts = $AssetsFontsGen();
static const $AssetsImagesGen images = $AssetsImagesGen();
}
@Hwan-seok
You can generate const via setting the flutter_gen.assets.style
.
https://github.com/FlutterGen/flutter_gen/issues/185#issuecomment-1006183927
Yes, I am aware of that.
But the whole assets are in the one class named Assets
and the subcategory image
is in the property name.
The reason why we are using .
separated style is that it divides the asset categories greatly.
It will be great if they are separated as follows.
AssetImages.chip1
AssetJsons.accounts
AssetLotties.fire
now i get
i want this
if image path string is AssetGenImage i can't make the widget const