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

Add support for flutter shaders #596

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 0 additions & 1 deletion packages/command/bin/flutter_gen_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_gen_core/flutter_generator.dart';
import 'package:flutter_gen_core/utils/cast.dart';
import 'package:flutter_gen_core/version.gen.dart';


void main(List<String> args) {
final parser = ArgParser();
parser.addOption(
Expand Down
4 changes: 2 additions & 2 deletions packages/command/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_gen
description: The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.
version: 5.8.0
version: 5.9.0
YaroCabbage marked this conversation as resolved.
Show resolved Hide resolved
homepage: https://github.com/FlutterGen/flutter_gen
repository: https://github.com/FlutterGen/flutter_gen
documentation: https://github.com/FlutterGen/flutter_gen
Expand All @@ -13,7 +13,7 @@ executables:
fluttergen: flutter_gen_command

dependencies:
flutter_gen_core: 5.8.0
flutter_gen_core: 5.9.0
args: ^2.0.0

dev_dependencies:
Expand Down
1 change: 0 additions & 1 deletion packages/command/test/flutter_gen_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:flutter_gen_core/version.gen.dart';
import 'package:test/test.dart';
import 'package:test_process/test_process.dart';


final separator = Platform.pathSeparator;

void main() {
Expand Down
14 changes: 14 additions & 0 deletions packages/core/lib/flutter_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:dart_style/dart_style.dart';
import 'package:flutter_gen_core/generators/assets_generator.dart';
import 'package:flutter_gen_core/generators/colors_generator.dart';
import 'package:flutter_gen_core/generators/fonts_generator.dart';
import 'package:flutter_gen_core/generators/shaders_generator.dart';
import 'package:flutter_gen_core/settings/config.dart';
import 'package:flutter_gen_core/utils/file.dart';
import 'package:path/path.dart';
Expand All @@ -13,13 +14,15 @@ class FlutterGenerator {
this.pubspecFile, {
this.buildFile,
this.assetsName = 'assets.gen.dart',
this.shadersName = 'shaders.gen.dart',
YaroCabbage marked this conversation as resolved.
Show resolved Hide resolved
this.colorsName = 'colors.gen.dart',
this.fontsName = 'fonts.gen.dart',
});

final File pubspecFile;
final File? buildFile;
final String assetsName;
final String shadersName;
final String colorsName;
final String fontsName;

Expand Down Expand Up @@ -69,6 +72,17 @@ class FlutterGenerator {
stdout.writeln('[FlutterGen] Generated: $assetsPath');
}

if (flutterGen.shaders.enabled && flutter.shaders.isNotEmpty) {
final generated = await generateShaders(
ShadersGenConfig.fromConfig(pubspecFile, config),
formatter,
);
final shadersPath =
normalize(join(pubspecFile.parent.path, output, shadersName));
writer(generated, shadersPath);
stdout.writeln('[FlutterGen] Generated: $shadersPath');
}

if (flutterGen.fonts.enabled && flutter.fonts.isNotEmpty) {
final generated = generateFonts(
FontsGenConfig.fromConfig(config),
Expand Down
602 changes: 602 additions & 0 deletions packages/core/lib/generators/shaders_generator.dart

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions packages/core/lib/settings/config_default.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ flutter_gen:
class_name: Assets
exclude: []

shaders:
# Optional
enabled: true
# Optional
outputs:
# Optional
# Set to true if you want this package to be a package dependency
# See: https://flutter.dev/docs/development/ui/assets-and-images#from-packages
package_parameter_enabled: false
# Optional
# Available values:
# - camel-case
# - snake-case
# - dot-delimiter
style: dot-delimiter
class_name: Shaders
exclude: []

fonts:
# Optional
enabled: true
Expand All @@ -55,4 +73,6 @@ flutter:
assets: []
# See: https://flutter.dev/docs/cookbook/design/fonts#2-declare-the-font-in-the-pubspec
fonts: []
# See: https://docs.flutter.dev/ui/design/graphics/fragment-shaders
shaders: []
''';
19 changes: 19 additions & 0 deletions packages/core/lib/settings/flavored_shader.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class FlavoredShader {
const FlavoredShader({
required this.path,
this.flavors = const {},
});

final String path;
final Set<String> flavors;

FlavoredShader copyWith({String? path, Set<String>? flavors}) {
return FlavoredShader(
path: path ?? this.path,
flavors: flavors ?? this.flavors,
);
}

@override
String toString() => 'FlavoredShader(path: $path, flavors: $flavors)';
}
8 changes: 8 additions & 0 deletions packages/core/lib/settings/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ class Flutter {
Flutter({
required this.assets,
required this.fonts,
required this.shaders,
});

@JsonKey(name: 'assets', required: true)
final List<Object> assets;

@JsonKey(name: 'shaders', required: true)
final List<Object> shaders;

@JsonKey(name: 'fonts', required: true)
final List<FlutterFonts> fonts;

Expand All @@ -57,6 +61,7 @@ class FlutterGen {
required this.lineLength,
required this.parseMetadata,
required this.assets,
required this.shaders,
required this.fonts,
required this.integrations,
required this.colors,
Expand All @@ -74,6 +79,9 @@ class FlutterGen {
@JsonKey(name: 'assets', required: true)
final FlutterGenAssets assets;

@JsonKey(name: 'shaders', required: true)
final FlutterGenAssets shaders;

@JsonKey(name: 'fonts', required: true)
final FlutterGenFonts fonts;

Expand Down
7 changes: 6 additions & 1 deletion packages/core/lib/settings/pubspec.g.dart

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

Loading