Closed Petri-Oosthuizen closed 1 year ago
You probably are actually using flutter_svg 2.0.3, which made clipBehavior
non-null. Your generated assets will need to specify a clip behavior or not specify null for it.
That said, I think it's probably fine to make clipBehavior
nullable again if it's really disruptive... Let me knwo.
You are correct, I was indeed using flutter_svg >= 2.0.3, pinning it to 2.0.2 fixed the problem.
The error comes from within the generated file, assets.gen.dart
, however. Setting the clipBehavior
in SvgPicture.asset
does unfortunately not solve the problem and I'm not setting clipBehavior
to null
anywhere.
Here's a snippet from the generated file with the error:
class SvgGenImage {
const SvgGenImage(this._assetName);
final String _assetName;
SvgPicture svg({
Key? key,
bool matchTextDirection = false,
AssetBundle? bundle,
String? package,
double? width,
double? height,
BoxFit fit = BoxFit.contain,
AlignmentGeometry alignment = Alignment.center,
bool allowDrawingOutsideViewBox = false,
WidgetBuilder? placeholderBuilder,
String? semanticsLabel,
bool excludeFromSemantics = false,
SvgTheme theme = const SvgTheme(),
ColorFilter? colorFilter,
@deprecated Color? color,
@deprecated BlendMode colorBlendMode = BlendMode.srcIn,
@deprecated Clip? clipBehavior,
@deprecated bool cacheColorFilter = false,
}) {
return SvgPicture.asset(
_assetName,
key: key,
matchTextDirection: matchTextDirection,
bundle: bundle,
package: package,
width: width,
height: height,
fit: fit,
alignment: alignment,
allowDrawingOutsideViewBox: allowDrawingOutsideViewBox,
placeholderBuilder: placeholderBuilder,
semanticsLabel: semanticsLabel,
excludeFromSemantics: excludeFromSemantics,
theme: theme,
colorFilter: colorFilter,
color: color,
colorBlendMode: colorBlendMode,
clipBehavior: clipBehavior, // Error: The argument type 'Clip?' can't be assigned to the parameter type 'Clip' because 'Clip?' is nullable and 'Clip' isn't.
cacheColorFilter: cacheColorFilter,
);
}
Either change this line:
clipBehavior: clipBehavior, // Error: The argument type 'Clip?' can't be assigned to the parameter type 'Clip' because 'Clip?' is nullable and 'Clip' isn't.
to
clipBehavior: clipBehavior ?? Clip.hardEdge
or this line:
@deprecated Clip? clipBehavior,
to
Clip clipBehavior = Clip.hardEdge
This is compatible with both 2.0.2 and 2.0.3.
I did not write this code. It was generated when I ran
flutter pub run build_runner build --delete-conflicting-outputs
Edit: I realised I should direct this problem towards flutter_gen_runner's flutter_svg integration.
Getting the following error after upgrading to Flutter 3.7.7:
lib/core/gen/assets.gen.dart:253:21: Error: The argument type 'Clip?' can't be assigned to the parameter type 'Clip' because 'Clip?' is nullable and 'Clip' isn't.