Skip to content

Commit

Permalink
feat: Add svg support for flutter_gen and add CatalystSvgPicture wr…
Browse files Browse the repository at this point in the history
…apper.
  • Loading branch information
coire1 committed May 16, 2024
1 parent d00fa4a commit 00120c0
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart';

/// [CatalystSvgPicture] is a wrapper around [SvgPicture.asset] that 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 {
static SvgPicture 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,
}) {
return SvgPicture.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 00120c0

Please sign in to comment.