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

SVG from string not rendering image from url #819

Open
JoakoV3 opened this issue Dec 16, 2022 · 1 comment
Open

SVG from string not rendering image from url #819

JoakoV3 opened this issue Dec 16, 2022 · 1 comment

Comments

@JoakoV3
Copy link

JoakoV3 commented Dec 16, 2022

I have these markers in google maps

googel maps markers

I am generating them from an svg with an <image> that has a network image.

The problem is, the markers image that should be inside is not being displayed.

Here's the code that I use to generate the marker:

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart' show BitmapDescriptor;
import 'dart:ui' as ui;

Future<BitmapDescriptor> getAssetImageMarker(String networkImage) async {
  Size size = const Size(30, 30);
  String svgString = '''
    <svg width="100" height="100" >
      <defs>
        <pattern id="image-pattern" x="0" y="0" width="100" height="100" patternUnits="userSpaceOnUse" >
          <image href="https://images.unsplash.com/photo-1608848461950-0fe51dfc41cb" x="0" y="0" width="100" height="120" />
        </pattern>
      </defs>
      <circle cx="50" cy="50" r="40" stroke="orange" stroke-width="4" fill="url(#image-pattern)" />
    </svg>
''';

  final svgDrawableRoot = await svg.fromSvgString(svgString, 'debug: ${svgString.codeUnits}');

  final ratio = ui.window.devicePixelRatio.ceil();
  final width = size.width.ceil() * ratio;
  final height = size.height.ceil() * ratio;
  final picture = svgDrawableRoot.toPicture(
    size: Size(
      width.toDouble(),
      height.toDouble(),
    ),
  );
  final image = await picture.toImage(width, height);
  final byteData = await image.toByteData(format: ui.ImageByteFormat.png);
  final uInt8List = byteData!.buffer.asUint8List();
  return BitmapDescriptor.fromBytes(uInt8List);
}

I don't know what the cause could be. Is this supported in svgFromString?

@Zurigan
Copy link

Zurigan commented Jan 5, 2023

As far as I can work out <pattern> is unsupported by flutter_svg, that entire element will be ignored by the svg parser with a unhandled element pattern; info message in your debug console.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants