Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Removed the AssetImage inheritance from AssetGenImage #229

Merged
merged 10 commits into from
May 20, 2022
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Example results of `assets/images/chip.jpg`:

```dart
Widget build(BuildContext context) {
return Image(image: Assets.images.chip);
return Assets.images.chip.image();
}

Widget build(BuildContext context) {
Expand Down
27 changes: 20 additions & 7 deletions example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// FlutterGen
/// *****************************************************

// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: directives_ordering,unnecessary_import

Expand Down Expand Up @@ -132,19 +133,23 @@ class Assets {
static const $PicturesGen pictures = $PicturesGen();
}

class AssetGenImage extends AssetImage {
const AssetGenImage(String assetName) : super(assetName);
class AssetGenImage {
const AssetGenImage(this._assetName);

final String _assetName;

Image image({
Key? key,
AssetBundle? bundle,
ImageFrameBuilder? frameBuilder,
ImageLoadingBuilder? loadingBuilder,
ImageErrorWidgetBuilder? errorBuilder,
String? semanticLabel,
bool excludeFromSemantics = false,
double? scale = 1.0,
double? width,
double? height,
Color? color,
Animation<double>? opacity,
BlendMode? colorBlendMode,
BoxFit? fit,
AlignmentGeometry alignment = Alignment.center,
Expand All @@ -153,19 +158,24 @@ class AssetGenImage extends AssetImage {
bool matchTextDirection = false,
bool gaplessPlayback = false,
bool isAntiAlias = false,
String? package,
FilterQuality filterQuality = FilterQuality.low,
int? cacheWidth,
int? cacheHeight,
}) {
return Image(
return Image.asset(
_assetName,
key: key,
image: this,
bundle: bundle,
frameBuilder: frameBuilder,
loadingBuilder: loadingBuilder,
errorBuilder: errorBuilder,
semanticLabel: semanticLabel,
excludeFromSemantics: excludeFromSemantics,
scale: scale,
width: width,
height: height,
color: color,
opacity: opacity,
colorBlendMode: colorBlendMode,
fit: fit,
alignment: alignment,
Expand All @@ -174,11 +184,14 @@ class AssetGenImage extends AssetImage {
matchTextDirection: matchTextDirection,
gaplessPlayback: gaplessPlayback,
isAntiAlias: isAntiAlias,
package: package,
filterQuality: filterQuality,
cacheWidth: cacheWidth,
cacheHeight: cacheHeight,
);
}

String get path => assetName;
String get path => _assetName;
}

class SvgGenImage {
Expand Down
1 change: 1 addition & 0 deletions example/lib/gen/colors.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// FlutterGen
/// *****************************************************

// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: directives_ordering,unnecessary_import

Expand Down
1 change: 1 addition & 0 deletions example/lib/gen/fonts.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/// FlutterGen
/// *****************************************************

// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: directives_ordering,unnecessary_import

Expand Down
6 changes: 5 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:example_resources/gen/assets.gen.dart' as res;

import 'gen/assets.gen.dart';
import 'gen/colors.gen.dart';
Expand Down Expand Up @@ -37,7 +38,10 @@ void main() {
fit: BoxFit.contain,
),
),
Image(image: Assets.images.chip1),
Assets.images.chip1.image(),
// Use from example_resource package.
res.Assets.images.flutter3.image(),
res.Assets.images.dart.svg(),
Assets.images.icons.kmm.svg(key: const Key("kmm_svg")),
Assets.images.icons.fuchsia.svg(),
Assets.images.icons.paint.svg(
Expand Down
4 changes: 4 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ dependencies:

json_annotation: ^4.5.0
freezed_annotation: ^2.0.3

example_resources:
path: ../example_resources


dev_dependencies:
flutter_test:
Expand Down
10 changes: 10 additions & 0 deletions example_resources/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# example

A sample project using FlutterGen.

## Getting Started

```
cd ../flutter_gen
melos run pub:get
```
23 changes: 23 additions & 0 deletions example_resources/assets/images/dart.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example_resources/assets/images/flutter3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
139 changes: 139 additions & 0 deletions example_resources/lib/gen/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions example_resources/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: example_resources
description: A sample project using FlutterGen.

publish_to: 'none'

version: 1.0.0+2

environment:
sdk: '>=2.14.0 <3.0.0'
flutter: '>=2.5.0'

dependencies:
flutter:
sdk: flutter

flutter_svg: ^1.0.1

dev_dependencies:
build_runner: ^2.1.7
flutter_gen_runner: ^4.1.6

flutter_gen:
output: lib/gen/
line_length: 80

integrations:
flutter_svg: true

assets:
enabled: true
package_parameter_enabled: true

flutter:
assets:
- assets/images/
19 changes: 18 additions & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: FlutterGen
packages:
- packages/**
- example/*
- example_resources/*

ide:
intellij: true
Expand All @@ -28,7 +29,9 @@ scripts:
run: |
melos exec -- dart pub run build_runner build --delete-conflicting-outputs
select-package:
ignore: example
ignore:
- example
- example_resources
depends-on: 'build_runner'

build:
Expand All @@ -51,6 +54,20 @@ scripts:
select-package:
scope: example

example:res:command:
run: |
melos exec \
-- dart ../packages/command/bin/flutter_gen_command.dart --config pubspec.yaml
select-package:
scope: example_resources

example:res:build_runner:
run: |
melos exec \
-- flutter pub run build_runner build --delete-conflicting-outputs
select-package:
scope: example_resources

unit:test:
run: melos exec -- dart test
select-package:
Expand Down
Loading