Skip to content

Commit

Permalink
feat: Add svg support to flutter (#498)
Browse files Browse the repository at this point in the history
* feat: Add svg support for flutter_gen and add `CatalystSvgPicture` wrapper.

* feat: Add Catalyst SVG logo version.
  • Loading branch information
coire1 authored May 17, 2024
1 parent bca05c5 commit b73fbe6
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 40 deletions.
5 changes: 3 additions & 2 deletions catalyst_voices/lib/pages/coming_soon/logo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ class ComingSoonLogo extends StatelessWidget {
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
CatalystImage.asset(
VoicesAssets.images.logo.path,
CatalystSvgPicture.asset(
VoicesAssets.images.catalystLogo.path,
width: 202,
),
Container(
margin: const EdgeInsets.only(left: 13, bottom: 6),
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

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

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/widgets.dart';

/// [CatalystImage] is a wrapper around [Image.asset] that sets the package
/// property to `catalyst_voices_assets` by default.
/// This allows the package to be used without having to specify
/// the package name every time.
/// [CatalystImage] extends [Image] to have an asset constructor
/// tat sets the package property to `catalyst_voices_assets` by default.
/// This allows to use the asset without having to specify the package name
/// every time.
/// For more information, see [Image.asset].
final class CatalystImage {
static Image asset(
final class CatalystImage extends Image {
CatalystImage.asset(
String name, {
AssetBundle? bundle,
ImageFrameBuilder? frameBuilder,
Expand All @@ -30,31 +30,29 @@ final class CatalystImage {
FilterQuality filterQuality = FilterQuality.low,
int? cacheWidth,
int? cacheHeight,
}) {
return Image.asset(
name,
bundle: bundle,
frameBuilder: frameBuilder,
errorBuilder: errorBuilder,
semanticLabel: semanticLabel,
excludeFromSemantics: excludeFromSemantics,
scale: scale,
width: width,
height: height,
color: color,
opacity: opacity,
colorBlendMode: colorBlendMode,
fit: fit,
alignment: alignment,
repeat: repeat,
centerSlice: centerSlice,
matchTextDirection: matchTextDirection,
gaplessPlayback: gaplessPlayback,
isAntiAlias: isAntiAlias,
filterQuality: filterQuality,
cacheWidth: cacheWidth,
cacheHeight: cacheHeight,
package: package,
);
}
}) : super.asset(
name,
bundle: bundle,
frameBuilder: frameBuilder,
errorBuilder: errorBuilder,
semanticLabel: semanticLabel,
excludeFromSemantics: excludeFromSemantics,
scale: scale,
width: width,
height: height,
color: color,
opacity: opacity,
colorBlendMode: colorBlendMode,
fit: fit,
alignment: alignment,
repeat: repeat,
centerSlice: centerSlice,
matchTextDirection: matchTextDirection,
gaplessPlayback: gaplessPlayback,
isAntiAlias: isAntiAlias,
filterQuality: filterQuality,
cacheWidth: cacheWidth,
cacheHeight: cacheHeight,
package: package,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';

/// [CatalystSvgPicture] extends [SvgPicture] to have an asset constructor
/// tat sets the package property to `catalyst_voices_assets` by default.
/// This allows to use the asset without having to specify the package name
/// every time.
/// For more information, see [SvgPicture.asset].
final class CatalystSvgPicture extends SvgPicture {
CatalystSvgPicture.asset(
String name, {
AssetBundle? bundle,
String? semanticsLabel,
bool excludeFromSemantics = false,
double? width,
double? height,
BoxFit fit = BoxFit.contain,
Alignment alignment = Alignment.center,
bool matchTextDirection = false,
String package = 'catalyst_voices_assets',
bool allowDrawingOutsideViewBox = false,
Widget Function(BuildContext)? placeholderBuilder,
Clip clipBehavior = Clip.hardEdge,
SvgTheme? theme,
ColorFilter? colorFilter,
}) : super.asset(
name,
bundle: bundle,
semanticsLabel: semanticsLabel,
excludeFromSemantics: excludeFromSemantics,
width: width,
height: height,
fit: fit,
alignment: alignment,
matchTextDirection: matchTextDirection,
package: package,
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
placeholderBuilder: placeholderBuilder,
clipBehavior: clipBehavior,
theme: theme,
colorFilter: colorFilter,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export 'package:catalyst_voices_assets/generated/assets.gen.dart';
export 'package:catalyst_voices_assets/generated/colors.gen.dart';
export 'package:catalyst_voices_assets/generated/fonts.gen.dart';
export 'package:catalyst_voices_assets/src/catalyst_image.dart';
export 'package:catalyst_voices_assets/src/catalyst_svg_picture.dart';
5 changes: 4 additions & 1 deletion catalyst_voices/packages/catalyst_voices_assets/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ environment:
dependencies:
flutter:
sdk: flutter
flutter_svg: ^2.0.10+1

dev_dependencies:
build_runner: ^2.3.3
Expand Down Expand Up @@ -43,4 +44,6 @@ flutter_gen:
outputs:
class_name: VoicesColors
inputs:
- assets/colors/colors.xml
- assets/colors/colors.xml
integrations:
flutter_svg: true

0 comments on commit b73fbe6

Please sign in to comment.