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

Dependencies outdated #69

Open
Ahmadre opened this issue Jul 22, 2024 · 6 comments
Open

Dependencies outdated #69

Ahmadre opened this issue Jul 22, 2024 · 6 comments

Comments

@Ahmadre
Copy link

Ahmadre commented Jul 22, 2024

Resolving dependencies...
Because graphx >=1.0.5 depends on flutter_svg ^1.1.6 and hommage depends on flutter_svg ^2.0.10+1, graphx >=1.0.5 is forbidden.
So, because hommage depends on graphx ^1.0.12, version solving failed.

Would be great if you generally check your package dependencies and update it :).

@Ahmadre
Copy link
Author

Ahmadre commented Jul 22, 2024

Also:

And because graphx >=1.0.5 depends on http ^0.13.5, flutter_svg ^2.0.10+1 is incompatible with graphx >=1.0.5.

@roipeker
Copy link
Owner

I will try to update it later today, thanks for the report

@Ahmadre
Copy link
Author

Ahmadre commented Jul 22, 2024

Thank you for your awesome work ❤️

@roipeker
Copy link
Owner

Sorry to disappoint, but the effort is kinda big to upgrade flutter constraints to latest stable and the packages.
I don't have the time to do so, as it will bring some breaking changes to the GraphX API as well.
Will try to check it deeper during the week, maybe I manage to get some extra help, but I can't promise anything.

Will keep you posted here @Ahmadre.
In the meantime, did you try to use dependency_overrides to overcome the issue?

@Ahmadre
Copy link
Author

Ahmadre commented Jul 29, 2024

Sorry to disappoint, but the effort is kinda big to upgrade flutter constraints to latest stable and the packages. I don't have the time to do so, as it will bring some breaking changes to the GraphX API as well. Will try to check it deeper during the week, maybe I manage to get some extra help, but I can't promise anything.

Will keep you posted here @Ahmadre. In the meantime, did you try to use dependency_overrides to overcome the issue?

I know.... I had to fix your svg_utils implementation.

Here's my way to fix the breaking changes:

import 'dart:ui';

import 'package:flutter_svg/flutter_svg.dart' as svg;

import '../../graphx.dart';

/// Utilities to work with `flutter_svg`.
///
class SvgUtils {
  /// Factory constructor to ensure exception. Throws an exception if an attempt
  /// is made to instantiate this class.
  factory SvgUtils() {
    throw UnsupportedError(
      "Cannot instantiate SvgUtils. Use only static methods.",
    );
  }

  // Private constructor to prevent instantiation
  //SvgUtils._();

  /// Parses a raw SVG string into a [SvgData] object.
  ///
  /// The returned [SvgData] object contains information about the SVG content,
  /// such as whether it contains drawable content and its size and viewBox.
  /// To be used on [GSvgShape].
  static Future<SvgData> svgDataFromString(String rawSvg) async {
    final svgRoot = await svg.vg.loadPicture(svg.SvgStringLoader(rawSvg), null);
    var obj = SvgData();
    obj.hasContent = svgRoot.picture != null;
    obj.picture = svgRoot.picture;
    final image = await svgRoot.picture.toImage(svgRoot.size.width.toInt(), svgRoot.size.height.toInt());
    obj.viewBox = GRect.fromNative(
      Rect.fromCenter(center: Offset((image.width / 2).toDouble(), (image.height / 2).toDouble()), width: image.width.toDouble(), height: image.height.toDouble()),
    );
    obj.size = GRect(
      0,
      0,
      image.width.toDouble(),
      image.height.toDouble(),
    );
    return obj;
  }

  /// Parses a raw SVG string and draws it on  a [Canvas].
  ///
  /// The [scaleCanvas] parameter specifies whether the canvas should be scaled
  /// to fit the SVG viewbox. The [clipCanvas] parameter specifies whether the
  /// canvas should be clipped to the bounds of the viewBox attribute.
  /// The [scaleCanvasSize] parameter is used to specify the size to which the
  /// canvas should be scaled.
  static void svgStringToCanvas(
    String rawSvg,
    Canvas canvas, {
    bool scaleCanvas = true,
    bool clipCanvas = true,
    required Size scaleCanvasSize,
  }) async {
    final svgRoot = await svg.vg.loadPicture(svg.SvgStringLoader(rawSvg), null);
    // if (scaleCanvas) {
    //   svgRoot.size = scaleCanvasSize;
    // }
    // if (clipCanvas) {
    //   svgRoot.clipCanvasToViewBox(canvas);
    // }
    canvas.drawPicture(svgRoot.picture);
  }

  /// Parses a raw SVG string into a [Picture] object.
  ///
  /// The [size] parameter can be used to specify the size of the picture. The
  /// [colorFilter] parameter can be used to apply a color filter to the picture.
  /// If [clipToViewBox] is true, the picture will be clipped to the bounds of
  /// the viewBox attribute.
  static Future<Picture> svgStringToPicture(
    String rawSvg, {
    Size? size,
    ColorFilter? colorFilter,
    bool clipToViewBox = true,
  }) async {
    final svgRoot = await svg.vg.loadPicture(svg.SvgStringLoader(rawSvg), null);
    return svgRoot.picture;
  }

  /// Parses a raw SVG string and returns the corresponding `DrawableRoot`.
  static Future<svg.PictureInfo> svgStringToSvgDrawable(String rawSvg) async {
    return await svg.vg.loadPicture(svg.SvgStringLoader(rawSvg), null);
  }
}

@burhankhanzada
Copy link

any update on this?

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

3 participants