roipeker / graphx

GraphX package for Flutter.
https://pub.dev/packages/graphx
MIT License
496 stars 49 forks source link

Dependencies outdated #69

Open Ahmadre opened 3 months ago

Ahmadre commented 3 months ago
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 commented 3 months ago

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 commented 3 months ago

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

Ahmadre commented 3 months ago

Thank you for your awesome work ❤️

roipeker commented 3 months ago

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 commented 3 months ago

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 commented 1 month ago

any update on this?