interactable_svg 0.0.7

SDKflutter
Platformandroidioswindowslinuxmacosweb

Flutter package to interact with different regions of an SVG.

interactable SVG

A flutter package for interacting with different parts of an SVG.

example

Getting Started

In the pubspec.yaml of your Flutter project, add the following dependency:

dependencies:
  ...
  interactable_svg: any

In your library file add the following import:

import 'package:interactable_svg/interactable_svg/interactable_svg.dart';

Usage

Basic usage (rendering SVG from asset folder):

        InteractiveViewer(
          scaleEnabled: true,
          panEnabled: true,
          constrained: true,
          child:InteractableSvg(
            svgAddress: "assets/floor_map.svg",
            onChanged: (region) {
              setState(() {
                selectedRegion = region;

              });
            },

            width: double.infinity,
            height: double.infinity,
            toggleEnable: true,
            isMultiSelectable: false,
            dotColor: Colors.black,
            selectedColor: Colors.red.withOpacity(0.5),
            strokeColor: Colors.blue,
            unSelectableId: "bg",
            centerDotEnable:true ,
            centerTextEnable:true ,
            strokeWidth: 2.0,
            centerTextStyle: const TextStyle(fontSize: 12,color: Colors.black),


          ),
        )

Network usage (rendering SVG from an URL):

          InteractableSvg.network(
            svgAddress: "www.example.com",
            fileName: "/floor_map.svg",
            .
            .
          ),
        

String usage (rendering SVG from a String):

          InteractableSvg.string(
            svgAddress: "<svg> </svg>",
          
            .
            .
          ),
        

Also your SVG must follow the following pattern.For better understanding see the example SVG.

'.* id="(.*)" name="(.*)" .* d="(.*)"'
for example:
  <path id="118" name="room 9" class="st0" d="M55 508h101.26v330H55Z" />;

To select a region without clicking on the SVG see the below code.For better understanding check the example.

final GlobalKey<InteractableSvgState> key = GlobalKey();
InteractableSvg(
      key: mapKey,...)

key.currentState?.toggleButton(region);
key.currentState?.holdButton(region);

Props

propstypesdescription
keyKey?
svgAddressStringAddress of an SVG like "assets/floor_map.svg"
widthdouble?SVG width. Default value is double.infinity
heightdouble?SVG height. Default value is double.infinity
strokeColorColor?Color of the region borders
selectedColorColor?Color of the selected region
strokeWidthdouble?Width of the region borders
toggleEnablebool?Region selecting act as like toggle button
isMultiSelectablebool?select multiple regions at once
onChangedFunction(Region? region)Returns new region value when it changed
unSelectableIdString?Makes that region wi that id non selective
centerDotEnablebool?place a dot in the center of the region
centerTextEnablebool?place name of the region at the center of the region
centerTextStyleTextStyle?Style of name of the region
dotColorColor?Color of the dot in the center of the region

Author