Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added example/assets/flare/Penguin.flr
Binary file not shown.
Binary file added example/assets/movie/the_earth.mp4
Binary file not shown.
1 change: 1 addition & 0 deletions example/assets/unknown/unknown_mime_type.bk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is UNKNOWN MIME TYPE FILE.
21 changes: 21 additions & 0 deletions example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ class $PicturesGen {
AssetGenImage get chip5 => const AssetGenImage('pictures/chip5.jpg');
}

class $AssetsFlareGen {
const $AssetsFlareGen();

String get penguin => 'assets/flare/Penguin.flr';
}

class $AssetsImagesGen {
const $AssetsImagesGen();

Expand All @@ -31,6 +37,18 @@ class $AssetsJsonGen {
String get fruits => 'assets/json/fruits.json';
}

class $AssetsMovieGen {
const $AssetsMovieGen();

String get theEarth => 'assets/movie/the_earth.mp4';
}

class $AssetsUnknownGen {
const $AssetsUnknownGen();

String get unknownMimeType => 'assets/unknown/unknown_mime_type.bk';
}

class $AssetsImagesChip3Gen {
const $AssetsImagesChip3Gen();

Expand All @@ -57,8 +75,11 @@ class $AssetsImagesIconsGen {
class Assets {
Assets._();

static const $AssetsFlareGen flare = $AssetsFlareGen();
static const $AssetsImagesGen images = $AssetsImagesGen();
static const $AssetsJsonGen json = $AssetsJsonGen();
static const $AssetsMovieGen movie = $AssetsMovieGen();
static const $AssetsUnknownGen unknown = $AssetsUnknownGen();
static const $PicturesGen pictures = $PicturesGen();
}

Expand Down
10 changes: 10 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:example/gen/assets.gen.dart';
import 'package:example/gen/colors.gen.dart';
import 'package:example/gen/fonts.gen.dart';
import 'package:flare_flutter/flare_actor.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

Expand All @@ -22,6 +23,15 @@ void main() {
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
// Auto generated image from FlutterGen.
Container(
width: 200,
height: 200,
child: FlareActor(
Assets.flare.penguin,
animation: 'walk',
fit: BoxFit.contain,
),
),
Image(image: Assets.images.chip1),
Assets.images.icons.kmm.svg(key: Key("kmm_svg")),
Assets.images.icons.fuchsia.svg(),
Expand Down
14 changes: 14 additions & 0 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.10.11"
flare_dart:
dependency: transitive
description:
name: flare_dart
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.4"
flare_flutter:
dependency: "direct main"
description:
name: flare_flutter
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.6"
flutter:
dependency: "direct main"
description: flutter
Expand Down
4 changes: 4 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
sdk: flutter

flutter_svg: ^0.18.1
flare_flutter: ^2.0.6

dev_dependencies:
flutter_test:
Expand Down Expand Up @@ -57,6 +58,9 @@ flutter:
- assets/images/icons/paint.svg
- assets/json/fruits.json
- pictures/chip5.jpg
- assets/flare/
- assets/movie/
- assets/unknown/unknown_mime_type.bk
fonts:
- family: Raleway
fonts:
Expand Down
2 changes: 1 addition & 1 deletion lib/src/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ _Statement _createAssetTypeStatement(
value: '$childClassName\(\)',
isConstConstructor: true,
);
} else if (!assetType.isUnKnownMime) {
} else {
final integration = integrations.firstWhere(
(element) => element.mime == assetType.mime,
orElse: () => null,
Expand Down
25 changes: 25 additions & 0 deletions test/assets_gen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,31 @@ void main() {
expect(actual, expected);
});

test('Assets with Unknown mime type on pubspec.yaml', () async {
await FlutterGenerator(
File('test_resources/pubspec_unknown_mime_type.yaml'))
.build();
expect(
File('test_resources/lib/gen/assets.gen.dart').readAsStringSync(),
isNotEmpty,
);

final pubspec =
File('test_resources/pubspec_unknown_mime_type.yaml');
final config = await Config(pubspec).load();
final formatter = DartFormatter(
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');

final actual = generateAssets(
pubspec, formatter, config.flutterGen, config.flutter.assets);
final expected =
File('test_resources/actual_data/assets_unknown_mime_type.gen.dart')
.readAsStringSync()
.replaceAll('\r\n', '\n');

expect(actual, expected);
});

test('Assets with No lists on pubspec.yaml', () async {
final pubspec = File('test_resources/pubspec_assets_no_list.yaml');
final config = await Config(pubspec).load();
Expand Down
70 changes: 70 additions & 0 deletions test_resources/actual_data/assets_unknown_mime_type.gen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/// GENERATED CODE - DO NOT MODIFY BY HAND
/// *****************************************************
/// FlutterGen
/// *****************************************************

import 'package:flutter/widgets.dart';

class $AssetsUnknownGen {
const $AssetsUnknownGen();

String get unknownMimeType => 'assets/unknown/unknown_mime_type.bk';
}

class Assets {
Assets._();

static const $AssetsUnknownGen unknown = $AssetsUnknownGen();
}

class AssetGenImage extends AssetImage {
const AssetGenImage(String assetName)
: _assetName = assetName,
super(assetName);
final String _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;
}
1 change: 1 addition & 0 deletions test_resources/assets/unknown/unknown_mime_type.bk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file is UNKNOWN MIME TYPE FILE.
9 changes: 9 additions & 0 deletions test_resources/pubspec_unknown_mime_type.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: test

flutter_gen:
output: lib/gen/ # Optional (default: lib/gen/)
lineLength: 80 # Optional (default: 80)

flutter:
assets:
- assets/unknown/