@@ -49,10 +49,10 @@ class AssetsGenConfig {
4949 flutterGen.assets.outputs.packageParameterEnabled ? _packageName : '' ;
5050}
5151
52- String generateAssets (
52+ Future < String > generateAssets (
5353 AssetsGenConfig config,
5454 DartFormatter formatter,
55- ) {
55+ ) async {
5656 if (config.assets.isEmpty) {
5757 throw const InvalidSettingsException (
5858 'The value of "flutter/assets:" is incorrect.' ,
@@ -157,11 +157,14 @@ String generateAssets(
157157
158158 final classesBuffer = StringBuffer ();
159159 if (config.flutterGen.assets.outputs.isDotDelimiterStyle) {
160- classesBuffer.writeln (_dotDelimiterStyleDefinition (config, integrations));
160+ final definition = await _dotDelimiterStyleDefinition (config, integrations);
161+ classesBuffer.writeln (definition);
161162 } else if (config.flutterGen.assets.outputs.isSnakeCaseStyle) {
162- classesBuffer.writeln (_snakeCaseStyleDefinition (config, integrations));
163+ final definition = await _snakeCaseStyleDefinition (config, integrations);
164+ classesBuffer.writeln (definition);
163165 } else if (config.flutterGen.assets.outputs.isCamelCaseStyle) {
164- classesBuffer.writeln (_camelCaseStyleDefinition (config, integrations));
166+ final definition = await _camelCaseStyleDefinition (config, integrations);
167+ classesBuffer.writeln (definition);
165168 } else {
166169 throw 'The value of "flutter_gen/assets/style." is incorrect.' ;
167170 }
@@ -290,11 +293,11 @@ AssetType _constructAssetTree(
290293 return assetTypeMap['.' ]! ;
291294}
292295
293- _Statement ? _createAssetTypeStatement (
296+ Future < _Statement ?> _createAssetTypeStatement (
294297 AssetsGenConfig config,
295298 UniqueAssetType assetType,
296299 List <Integration > integrations,
297- ) {
300+ ) async {
298301 final childAssetAbsolutePath = join (config.rootPath, assetType.path);
299302 if (FileSystemEntity .isDirectorySync (childAssetAbsolutePath)) {
300303 final childClassName = '\$ ${assetType .path .camelCase ().capitalize ()}Gen' ;
@@ -308,9 +311,20 @@ _Statement? _createAssetTypeStatement(
308311 needDartDoc: false ,
309312 );
310313 } else if (! assetType.isIgnoreFile) {
311- final integration = integrations.firstWhereOrNull (
312- (element) => element.isSupport (assetType),
313- );
314+ Integration ? integration;
315+ for (final element in integrations) {
316+ final call = element.isSupport (assetType);
317+ final bool isSupport;
318+ if (call is Future <bool >) {
319+ isSupport = await call;
320+ } else {
321+ isSupport = call;
322+ }
323+ if (isSupport) {
324+ integration = element;
325+ break ;
326+ }
327+ }
314328 if (integration == null ) {
315329 var assetKey = assetType.posixStylePath;
316330 if (config.flutterGen.assets.outputs.packageParameterEnabled) {
@@ -342,10 +356,10 @@ _Statement? _createAssetTypeStatement(
342356}
343357
344358/// Generate style like Assets.foo.bar
345- String _dotDelimiterStyleDefinition (
359+ Future < String > _dotDelimiterStyleDefinition (
346360 AssetsGenConfig config,
347361 List <Integration > integrations,
348- ) {
362+ ) async {
349363 final rootPath = Directory (config.rootPath).absolute.uri.toFilePath ();
350364 final buffer = StringBuffer ();
351365 final className = config.flutterGen.assets.outputs.className;
@@ -374,29 +388,29 @@ String _dotDelimiterStyleDefinition(
374388 File (assetPath).parent.absolute.uri.toFilePath () == rootPath;
375389 // Handles directories, and explicitly handles root path assets.
376390 if (isDirectory || isRootAsset) {
377- final statements = assetType.children
378- .mapToUniqueAssetType (camelCase, justBasename: true )
379- .map (
380- (e) => _createAssetTypeStatement (
381- config,
382- e,
383- integrations,
391+ final List <_Statement ?> results = await Future .wait (
392+ assetType.children
393+ .mapToUniqueAssetType (camelCase, justBasename: true )
394+ .map (
395+ (e) => _createAssetTypeStatement (
396+ config,
397+ e,
398+ integrations,
399+ ),
384400 ),
385- )
386- .whereType <_Statement >()
387- .toList ();
401+ );
402+ final statements = results.whereType <_Statement >().toList ();
388403
389404 if (assetType.isDefaultAssetsDirectory) {
390405 assetsStaticStatements.addAll (statements);
391406 } else if (! isDirectory && isRootAsset) {
392407 // Creates explicit statement.
393- assetsStaticStatements.add (
394- _createAssetTypeStatement (
395- config,
396- UniqueAssetType (assetType: assetType, style: camelCase),
397- integrations,
398- )! ,
408+ final statement = await _createAssetTypeStatement (
409+ config,
410+ UniqueAssetType (assetType: assetType, style: camelCase),
411+ integrations,
399412 );
413+ assetsStaticStatements.add (statement! );
400414 } else {
401415 final className = '\$ ${assetType .path .camelCase ().capitalize ()}Gen' ;
402416 buffer.writeln (
@@ -437,59 +451,60 @@ String _dotDelimiterStyleDefinition(
437451 return buffer.toString ();
438452}
439453
440- /// Generate style like Assets.fooBar
441- String _camelCaseStyleDefinition (
454+ /// Generate style like Assets.foo_bar
455+ Future < String > _snakeCaseStyleDefinition (
442456 AssetsGenConfig config,
443457 List <Integration > integrations,
444458) {
445459 return _flatStyleDefinition (
446460 config,
447461 integrations,
448- camelCase ,
462+ snakeCase ,
449463 );
450464}
451465
452- /// Generate style like Assets.foo_bar
453- String _snakeCaseStyleDefinition (
466+ /// Generate style like Assets.fooBar
467+ Future < String > _camelCaseStyleDefinition (
454468 AssetsGenConfig config,
455469 List <Integration > integrations,
456470) {
457471 return _flatStyleDefinition (
458472 config,
459473 integrations,
460- snakeCase ,
474+ camelCase ,
461475 );
462476}
463477
464- String _flatStyleDefinition (
478+ Future < String > _flatStyleDefinition (
465479 AssetsGenConfig config,
466480 List <Integration > integrations,
467481 String Function (String ) style,
468- ) {
482+ ) async {
469483 final List <FlavoredAsset > paths = _getAssetRelativePathList (
470484 config.rootPath,
471485 config.assets,
472486 config.exclude,
473487 );
474488 paths.sort (((a, b) => a.path.compareTo (b.path)));
475- final statements = paths
476- .map (
477- (assetPath) => AssetType (
478- rootPath: config.rootPath,
479- path: assetPath.path,
480- flavors: assetPath.flavors,
481- ),
482- )
483- .mapToUniqueAssetType (style)
484- .map (
485- (e) => _createAssetTypeStatement (
486- config,
487- e,
488- integrations,
489+ final List <_Statement ?> results = await Future .wait (
490+ paths
491+ .map (
492+ (assetPath) => AssetType (
493+ rootPath: config.rootPath,
494+ path: assetPath.path,
495+ flavors: assetPath.flavors,
496+ ),
497+ )
498+ .mapToUniqueAssetType (style)
499+ .map (
500+ (e) => _createAssetTypeStatement (
501+ config,
502+ e,
503+ integrations,
504+ ),
489505 ),
490- )
491- .whereType <_Statement >()
492- .toList ();
506+ );
507+ final statements = results.whereType <_Statement >().toList ();
493508 final className = config.flutterGen.assets.outputs.className;
494509 final String ? packageName = generatePackageNameForConfig (config);
495510 return _flatStyleAssetsClassDefinition (className, statements, packageName);
0 commit comments