Skip to content

Commit 75e3629

Browse files
committed
fix(assets): #60 Set files like .DS_Store to the ignore list.
1 parent d5502bb commit 75e3629

File tree

13 files changed

+125
-6
lines changed

13 files changed

+125
-6
lines changed

example/assets/unknown/.DS_Store

6 KB
Binary file not shown.

example/assets/unknown/dummy.DS_Store

Whitespace-only changes.

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ packages:
222222
path: ".."
223223
relative: true
224224
source: path
225-
version: "1.2.2"
225+
version: "1.3.0"
226226
flutter_svg:
227227
dependency: "direct main"
228228
description:

example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ flutter:
6161
- pictures/chip5.jpg
6262
- assets/flare/
6363
- assets/movie/
64-
- assets/unknown/unknown_mime_type.bk
64+
- assets/unknown/
6565
fonts:
6666
- family: Raleway
6767
fonts:

lib/src/generators/assets_generator.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:io';
33

44
import 'package:dart_style/dart_style.dart';
55
import 'package:dartx/dartx.dart';
6-
import 'package:flutter_gen/src/generators/integrations/flare_integration.dart';
76
import 'package:path/path.dart';
87

98
import '../settings/asset_type.dart';
@@ -12,6 +11,7 @@ import '../settings/flutter_gen.dart';
1211
import '../utils/error.dart';
1312
import '../utils/string.dart';
1413
import 'generator_helper.dart';
14+
import 'integrations/flare_integration.dart';
1515
import 'integrations/integration.dart';
1616
import 'integrations/svg_integration.dart';
1717

@@ -142,7 +142,7 @@ _Statement _createAssetTypeStatement(
142142
value: '$childClassName\(\)',
143143
isConstConstructor: true,
144144
);
145-
} else {
145+
} else if (!assetType.isIgnoreFile) {
146146
final integration = integrations.firstWhere(
147147
(element) => element.isSupport(assetType),
148148
orElse: () => null,

lib/src/settings/asset_type.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ class AssetType {
2929
}
3030
}
3131

32+
bool get isIgnoreFile {
33+
switch (baseName) {
34+
case '.DS_Store':
35+
return true;
36+
}
37+
38+
switch (extension) {
39+
case '.DS_Store':
40+
case '.swp':
41+
return true;
42+
}
43+
44+
return false;
45+
}
46+
3247
bool get isUnKnownMime => mime == null;
3348

3449
String get extension => p.extension(path);

pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,4 +492,4 @@ packages:
492492
source: hosted
493493
version: "2.2.1"
494494
sdks:
495-
dart: ">=2.7.0 <3.0.0"
495+
dart: ">=2.9.0 <3.0.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors:
1010
- Mao Yufeng <[email protected]>
1111

1212
environment:
13-
sdk: '>=2.7.0 <3.0.0'
13+
sdk: '>=2.9.0 <3.0.0'
1414

1515
executables:
1616
fluttergen: flutter_gen_command

test/assets_gen_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ void main() {
9090
expect(actual, expected);
9191
});
9292

93+
test('Assets with ignore files on pubspec.yaml', () async {
94+
await FlutterGenerator(
95+
File('test_resources/pubspec_ignore_files.yaml'))
96+
.build();
97+
expect(
98+
File('test_resources/lib/gen/assets.gen.dart').readAsStringSync(),
99+
isNotEmpty,
100+
);
101+
102+
final pubspec =
103+
File('test_resources/pubspec_ignore_files.yaml');
104+
final config = await Config(pubspec).load();
105+
final formatter = DartFormatter(
106+
pageWidth: config.flutterGen.lineLength, lineEnding: '\n');
107+
108+
final actual = generateAssets(
109+
pubspec, formatter, config.flutterGen, config.flutter.assets);
110+
final expected =
111+
File('test_resources/actual_data/assets_ignore_files.gen.dart')
112+
.readAsStringSync()
113+
.replaceAll('\r\n', '\n');
114+
115+
expect(actual, expected);
116+
});
117+
93118
test('Assets with No lists on pubspec.yaml', () async {
94119
final pubspec = File('test_resources/pubspec_assets_no_list.yaml');
95120
final config = await Config(pubspec).load();
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/// GENERATED CODE - DO NOT MODIFY BY HAND
2+
/// *****************************************************
3+
/// FlutterGen
4+
/// *****************************************************
5+
6+
import 'package:flutter/widgets.dart';
7+
8+
class $AssetsUnknownGen {
9+
const $AssetsUnknownGen();
10+
}
11+
12+
class Assets {
13+
Assets._();
14+
15+
static const $AssetsUnknownGen unknown = $AssetsUnknownGen();
16+
}
17+
18+
class AssetGenImage extends AssetImage {
19+
const AssetGenImage(String assetName)
20+
: _assetName = assetName,
21+
super(assetName);
22+
final String _assetName;
23+
24+
Image image({
25+
Key key,
26+
ImageFrameBuilder frameBuilder,
27+
ImageLoadingBuilder loadingBuilder,
28+
ImageErrorWidgetBuilder errorBuilder,
29+
String semanticLabel,
30+
bool excludeFromSemantics = false,
31+
double width,
32+
double height,
33+
Color color,
34+
BlendMode colorBlendMode,
35+
BoxFit fit,
36+
AlignmentGeometry alignment = Alignment.center,
37+
ImageRepeat repeat = ImageRepeat.noRepeat,
38+
Rect centerSlice,
39+
bool matchTextDirection = false,
40+
bool gaplessPlayback = false,
41+
bool isAntiAlias = false,
42+
FilterQuality filterQuality = FilterQuality.low,
43+
}) {
44+
return Image(
45+
key: key,
46+
image: this,
47+
frameBuilder: frameBuilder,
48+
loadingBuilder: loadingBuilder,
49+
errorBuilder: errorBuilder,
50+
semanticLabel: semanticLabel,
51+
excludeFromSemantics: excludeFromSemantics,
52+
width: width,
53+
height: height,
54+
color: color,
55+
colorBlendMode: colorBlendMode,
56+
fit: fit,
57+
alignment: alignment,
58+
repeat: repeat,
59+
centerSlice: centerSlice,
60+
matchTextDirection: matchTextDirection,
61+
gaplessPlayback: gaplessPlayback,
62+
isAntiAlias: isAntiAlias,
63+
filterQuality: filterQuality,
64+
);
65+
}
66+
67+
String get path => _assetName;
68+
}

0 commit comments

Comments
 (0)