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 gen class name #290

Merged
merged 4 commits into from
Sep 12, 2022
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
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
"--config",
"${workspaceFolder}/example/pubspec.yaml"
]
},
}
]
}
}
2 changes: 1 addition & 1 deletion example/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>9.0</string>
<string>11.0</string>
</dict>
</plist>
48 changes: 24 additions & 24 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,11 @@ PODS:
- GoogleUtilities/Network (~> 7.7)
- "GoogleUtilities/NSData+zlib (~> 7.7)"
- nanopb (~> 2.30908.0)
- GoogleDataTransport (9.1.4):
- GoogleDataTransport (9.2.0):
- GoogleUtilities/Environment (~> 7.7)
- nanopb (< 2.30910.0, >= 2.30908.0)
- PromisesObjC (< 3.0, >= 1.2)
- GoogleSignIn (6.2.1):
- GoogleSignIn (6.2.3):
- AppAuth (~> 1.5)
- GTMAppAuth (~> 1.3)
- GTMSessionFetcher/Core (~> 1.1)
Expand Down Expand Up @@ -244,15 +244,15 @@ PODS:
- Flutter
- is_firebase_test_lab_activated (0.0.1):
- Flutter
- libwebp (1.2.1):
- libwebp/demux (= 1.2.1)
- libwebp/mux (= 1.2.1)
- libwebp/webp (= 1.2.1)
- libwebp/demux (1.2.1):
- libwebp (1.2.3):
- libwebp/demux (= 1.2.3)
- libwebp/mux (= 1.2.3)
- libwebp/webp (= 1.2.3)
- libwebp/demux (1.2.3):
- libwebp/webp
- libwebp/mux (1.2.1):
- libwebp/mux (1.2.3):
- libwebp/demux
- libwebp/webp (1.2.1)
- libwebp/webp (1.2.3)
- local_auth_ios (0.0.1):
- Flutter
- Mantle (2.2.0):
Expand All @@ -272,14 +272,14 @@ PODS:
- Flutter
- permission_handler_apple (9.0.4):
- Flutter
- PromisesObjC (2.1.0)
- PromisesObjC (2.1.1)
- ReachabilitySwift (5.0.0)
- SDWebImage (5.12.5):
- SDWebImage/Core (= 5.12.5)
- SDWebImage/Core (5.12.5)
- SDWebImageWebPCoder (0.8.4):
- SDWebImage (5.13.2):
- SDWebImage/Core (= 5.13.2)
- SDWebImage/Core (5.13.2)
- SDWebImageWebPCoder (0.9.1):
- libwebp (~> 1.0)
- SDWebImage/Core (~> 5.10)
- SDWebImage/Core (~> 5.13)
- Sentry (7.11.0):
- Sentry/Core (= 7.11.0)
- Sentry/Core (7.11.0)
Expand Down Expand Up @@ -518,7 +518,7 @@ SPEC CHECKSUMS:
FirebaseMessaging: 5ebc42d281567658a2cb72b9ef3506e4a1a1a6e4
FirebasePerformance: ecaa182ba9c6654e2e3813e759036d80e22269a8
FirebaseRemoteConfig: a5d9188d8f57f602636f111eca6460ebe32b9b71
Flutter: 50d75fe2f02b26cc09d224853bb45737f8b3214a
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
flutter_facebook_auth: a030aef1c2552fdc7cb090acc716ac836e3bb63c
flutter_image_compress: fd2b476345226e1a10ea352fa306af95704642c1
flutter_inappwebview: bfd58618f49dc62f2676de690fc6dcda1d6c3721
Expand All @@ -527,10 +527,10 @@ SPEC CHECKSUMS:
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
geocoding: 32cfcdb16d38d907caaba65e2e42ad10d38bee58
geolocator_apple: cc556e6844d508c95df1e87e3ea6fa4e58c50401
google_sign_in_ios: 90eec6616c4c2105b9f9fe5c774773d13565b504
google_sign_in_ios: 4f85eb9f937450765c8573bb85fd8cd6a5af675c
GoogleAppMeasurement: 71156240babd3cc6ced03e0d54816f01a880c730
GoogleDataTransport: 5fffe35792f8b96ec8d6775f5eccd83c998d5a3b
GoogleSignIn: 9c69f4188921d8f789816e4c99ba2a1f5f868ddc
GoogleDataTransport: 1c8145da7117bd68bbbed00cf304edb6a24de00f
GoogleSignIn: f4d3939cc0d9264d7509c4b9a924a6c987e30b54
GoogleUtilities: e0913149f6b0625b553d70dae12b49fc62914fd1
GTMAppAuth: 4d8f864896f3646f0c33baf38a28362f4c601e15
GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba
Expand All @@ -539,7 +539,7 @@ SPEC CHECKSUMS:
in_app_review: 4a97249f7a2f539a0f294c2d9196b7fe35e49541
integration_test: a1e7d09bd98eca2fc37aefd79d4f41ad37bdbbe5
is_firebase_test_lab_activated: 84effe92e5d79a58455a2861b5e1ba688016cf57
libwebp: 98a37e597e40bfdb4c911fc98f2c53d0b12d05fc
libwebp: 60305b2e989864154bd9be3d772730f08fc6a59c
local_auth_ios: 0d333dde7780f669e66f19d2ff6005f3ea84008d
Mantle: c5aa8794a29a022dfbbfc9799af95f477a69b62d
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
Expand All @@ -548,10 +548,10 @@ SPEC CHECKSUMS:
package_info_plus: 6c92f08e1f853dc01228d6f553146438dafcd14e
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02
permission_handler_apple: 44366e37eaf29454a1e7b1b7d736c2cceaeb17ce
PromisesObjC: 99b6f43f9e1044bd87a95a60beff28c2c44ddb72
PromisesObjC: ab77feca74fa2823e7af4249b8326368e61014cb
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
SDWebImage: 0905f1b7760fc8ac4198cae0036600d67478751e
SDWebImageWebPCoder: f93010f3f6c031e2f8fb3081ca4ee6966c539815
SDWebImage: 72f86271a6f3139cc7e4a89220946489d4b9a866
SDWebImageWebPCoder: 18503de6621dd2c420d680e33d46bf8e1d5169b0
Sentry: 0c5cd63d714187b4a39c331c1f0eb04ba7868341
sentry_flutter: efb3df2c203cd03aad255892a8d628a458656d14
share_plus: 056a1e8ac890df3e33cb503afffaf1e9b4fbae68
Expand All @@ -568,4 +568,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: cc1f88378b4bfcf93a6ce00d2c587857c6008d3b

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
6 changes: 3 additions & 3 deletions example/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down Expand Up @@ -425,7 +425,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -474,7 +474,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SUPPORTED_PLATFORMS = iphoneos;
Expand Down
4 changes: 2 additions & 2 deletions example/lib/gen/assets.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ class $AssetsImagesIconsGen {
SvgGenImage get paint => const SvgGenImage('assets/images/icons/paint.svg');
}

class Assets {
Assets._();
class MyAssets {
MyAssets._();

static const $AssetsFlareGen flare = $AssetsFlareGen();
static const $AssetsImagesGen images = $AssetsImagesGen();
Expand Down
4 changes: 2 additions & 2 deletions example/lib/gen/colors.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import 'package:flutter/painting.dart';
import 'package:flutter/material.dart';

class ColorName {
ColorName._();
class MyColorName {
MyColorName._();

/// Color: #000000
static const Color black = Color(0xFF000000);
Expand Down
4 changes: 2 additions & 2 deletions example/lib/gen/fonts.gen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
// ignore_for_file: type=lint
// ignore_for_file: directives_ordering,unnecessary_import

class FontFamily {
FontFamily._();
class MyFontFamily {
MyFontFamily._();

/// Font family: Raleway
static const String raleway = 'Raleway';
Expand Down
34 changes: 16 additions & 18 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:example_resources/gen/assets.gen.dart' as res;
import 'package:flutter/material.dart';

import 'firebase_options.dart';
import 'gen/assets.gen.dart';
import 'gen/colors.gen.dart';
import 'gen/fonts.gen.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
// await Firebase.initializeApp(
// options: DefaultFirebaseOptions.currentPlatform,
// );

runApp(MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// Auto generated font from FlutterGen.
fontFamily: FontFamily.raleway,
primarySwatch: ColorName.crimsonRed,
fontFamily: MyFontFamily.raleway,
primarySwatch: MyColorName.crimsonRed,
),
home: Scaffold(
appBar: AppBar(
Expand All @@ -33,29 +31,29 @@ void main() async {
SizedBox(
width: 200,
height: 200,
child: Assets.flare.penguin.flare(
child: MyAssets.flare.penguin.flare(
animation: 'walk',
fit: BoxFit.contain,
),
),
SizedBox(
width: 200,
height: 200,
child: Assets.rive.vehicles.rive(
child: MyAssets.rive.vehicles.rive(
fit: BoxFit.contain,
),
),
Assets.images.chip1.image(),
MyAssets.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(
MyAssets.images.icons.kmm.svg(key: const Key("kmm_svg")),
MyAssets.images.icons.fuchsia.svg(),
MyAssets.images.icons.paint.svg(
width: 120,
height: 120,
),
// Assets.pictures.chip5.image(
// MyAssets.pictures.chip5.image(
// key: const Key("chip5"),
// width: 120,
// height: 120,
Expand All @@ -65,11 +63,11 @@ void main() async {
'Hi there, I\'m FlutterGen',
style: TextStyle(
// Auto generated color from FlutterGen.
color: ColorName.black60,
color: MyColorName.black60,

// Auto generated font from FlutterGen.
fontFamily: FontFamily.robotoMono,
fontFamilyFallback: [FontFamily.raleway],
fontFamily: MyFontFamily.robotoMono,
fontFamilyFallback: [MyFontFamily.raleway],
),
),
],
Expand Down
12 changes: 10 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ dependencies:
local_auth: 2.0.1
flutter_hooks: 0.18.3
hooks_riverpod: 1.0.3
async: 2.8.2
# async: 2.9.0
dio: 4.0.6
connectivity_plus: 2.3.0
ua_client_hints: 1.1.0
Expand Down Expand Up @@ -131,16 +131,24 @@ flutter_gen:

# Assets.images.chip (default style)
# style: dot-delimiter
exclude:

outputs:
class_name: MyAssets

exclude:
- assets/images/chip3/chip3.jpg
- pictures/chip5.jpg
- assets/flare/

fonts:
enabled: true
outputs:
class_name: MyFontFamily

colors:
enabled: true
outputs:
class_name: MyColorName
inputs:
- assets/color/colors.xml
- assets/color/colors2.xml
Expand Down
7 changes: 2 additions & 5 deletions packages/core/lib/flutter_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ class FlutterGenerator {
}

if (flutterGen.fonts.enabled && flutter.fonts.isNotEmpty) {
final generated = generateFonts(
formatter,
flutter.fonts,
genFonts: flutterGen.fonts,
);
final generated =
generateFonts(formatter, flutter.fonts, flutterGen.fonts);
final fonts =
File(normalize(join(pubspecFile.parent.path, output, fontsName)));
writeAsString(generated, file: fonts);
Expand Down
14 changes: 7 additions & 7 deletions packages/core/lib/generators/assets_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ String _dotDelimiterStyleDefinition(
List<Integration> integrations,
) {
final buffer = StringBuffer();
final className = config.flutterGen.assets.outputs?.className;
final className = config.flutterGen.assets.outputs.className;
final assetRelativePathList = _getAssetRelativePathList(
config.rootPath,
config.assets,
Expand Down Expand Up @@ -328,12 +328,12 @@ String _flatStyleDefinition(
)
.whereType<_Statement>()
.toList();
final className = config.flutterGen.assets.outputs?.className;
final className = config.flutterGen.assets.outputs.className;
return _flatStyleAssetsClassDefinition(className, statements);
}

String _flatStyleAssetsClassDefinition(
String? className,
String className,
List<_Statement> statements,
) {
final statementsBlock =
Expand All @@ -344,18 +344,18 @@ String _flatStyleAssetsClassDefinition(
}

String _dotDelimiterStyleAssetsClassDefinition(
String? className,
String className,
List<_Statement> statements,
) {
final statementsBlock =
statements.map((statement) => statement.toStaticFieldString()).join('\n');
return _assetsClassDefinition(className, statementsBlock);
}

String _assetsClassDefinition(String? className, String statementsBlock) {
String _assetsClassDefinition(String className, String statementsBlock) {
return '''
class ${className ?? 'Assets'} {
${className ?? 'Assets'}._();
class $className {
$className._();

$statementsBlock
}
Expand Down
8 changes: 4 additions & 4 deletions packages/core/lib/generators/colors_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ import 'generator_helper.dart';
String generateColors(
File pubspecFile,
DartFormatter formatter,
FlutterGenColors genColors,
FlutterGenColors colorsConfig,
) {
if (genColors.inputs.isEmpty) {
if (colorsConfig.inputs.isEmpty) {
throw const InvalidSettingsException(
'The value of "flutter_gen/colors:" is incorrect.');
}

final buffer = StringBuffer();
final className = genColors.outputs?.className ?? 'ColorName';
final className = colorsConfig.outputs.className;
buffer.writeln(header);
buffer.writeln(ignore);
buffer.writeln("import 'package:flutter/painting.dart';");
Expand All @@ -34,7 +34,7 @@ String generateColors(
buffer.writeln();

final colorList = <_Color>[];
genColors.inputs
colorsConfig.inputs
.map((file) => ColorPath(join(pubspecFile.parent.path, file)))
.forEach((colorFile) {
final data = colorFile.file.readAsStringSync();
Expand Down
Loading