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

When using v1 version with flutter 3.16, svg files that have been converted to Image class and enlarged are not rendered correctly #1019

Open
SShayashi opened this issue Dec 14, 2023 · 0 comments

Comments

@SShayashi
Copy link

SShayashi commented Dec 14, 2023

Overview

After upgrading from flutter 3.13.9 to 3.16.0, svg files are not rendered correctly when converted to Image class.
We have confirmed that this problem occurs when using the v1 version of the library and that it works correctly when using the v2 version of the library, but we are raising this issue just in case.

expected result

※ Result of running with flutter 3.13.9

actual result

sample code
import 'dart:ui' as ui;

import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

const specifiedPlaceMarker = 'assets/specified_place_marker.svg';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key, required this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  ui.Image? myImage;
  String? svgString;

  @override
  void initState() {
    super.initState();
    createSpecifiedPlaceMarkerIcon();
  }

  Future<void> createSpecifiedPlaceMarkerIcon() async {
    String str = await DefaultAssetBundle.of(context).loadString(
      specifiedPlaceMarker,
    );
    setState(() {
      svgString = str;
    });
    DrawableRoot svgDrawableRoot = await svg.fromSvgString(
      str,
      'specifiedPlaceMarkerIcon',
    );
    const double scale = 3;
    double width = 46 * scale;
    double height = 46 * scale;

    ui.Picture picture = svgDrawableRoot.toPicture(
      size: Size(
        width,
        height,
      ),
    );

    ui.Image image = await picture.toImage(
      width.round(),
      height.round(),
    );
    setState(() {
      myImage = image;
    });
    return;
  }

  @override
  Widget build(BuildContext context) {
    if (myImage == null || svgString == null) {
      return Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: const Center(
          child: Text('loading image'),
        ),
      );
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('original image'),
            SvgPicture.string(svgString!),
            const Text('scaled image'),
            RawImage(image: myImage!),
          ],
        ),
      ),
    );
  }
}
specified_place_marker.svg

specified_place_marker

flutter doctor -v
[✓] Flutter (Channel stable, 3.16.0, on macOS 13.4 22F66 darwin-arm64, locale ja-JP)
    • Flutter version 3.16.0 on channel stable at /Users/01036096/fvm/versions/3.16.0
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db7ef5bf9f (4 weeks ago), 2023-11-15 11:25:44 -0800
    • Engine revision 74d16627b9
    • Dart version 3.2.0
    • DevTools version 2.28.2

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/01036096/Library/Android/sdk
    • Platform android-33, build-tools 33.0.2
    • ANDROID_HOME = /Users/01036096/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode14.1.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.85.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.78.0

[✓] Connected device (6 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554                        • android-arm64  • Android 12 (API 31) (emulator)
    • sdk gphone64 arm64 (mobile) • emulator-5556                        • android-arm64  • Android 14 (API 34) (emulator)
    • iPhone 13 (mobile)          • 6E990A07-BEEB-4FF2-8935-803C0DF47257 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-2 (simulator)
    • iPhone 14 Pro Max (mobile)  • 08DFB7BD-01AA-45DC-A8F3-9F61D45007E3 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-17-0 (simulator)
    • macOS (desktop)             • macos                                • darwin-arm64   • macOS 13.4 22F66 darwin-arm64
    • Chrome (web)                • chrome                               • web-javascript • Google Chrome 120.0.6099.109

[✓] Network resources
    • All expected network resources are available.

• No issues found!
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

1 participant