'How to make svg elements clickable in flutter

I'm new to flutter and I'm struggling for two day to make an svg elements clickable , the problem is that my svg image has more than 200 element that need to respond to clicks. I'll appreciate any help or clue to solve my problem.

this is my svg file



Solution 1:[1]

Bug is in the below lines of code

temp=arr[i];
arr[i]=arr[arr[i]+1];
arr[arr[i]+1]=temp;

Why there is bug :

suppose arr[0] is 0 and arr[1]=1
temp=arr[0]// now temp is 0
arr[i]=arr[arr[i]+1];// now arr[0] is 1 
arr[arr[i]+1]=temp;//arr[2] is now 0 and about arr[1] we are not setting it and arr[2] value is also lost

What is the solution :

Store the values before swapping :

int temp1=arr2[i];
int temp2=arr2[arr2[i]+1];
//swapping
arr2[arr2[i]+1]=temp1;
arr2[i]=temp2;//it should be below, don't assign arr2[i] earlier

Source with logical bug fixed :

#include <iostream>

using namespace std;

//swap
void swap(int &a,int &b){
    //cout<<"swap "<<a<<" "<<b<<endl;
    int temp=b;
    b=a;
    a=temp;
}

int main(){
    int n;
    cin>>n;
    //arr is swapped using swapped method
    int arr[n],i,temp;
    //arr2 is swapped using temp variable
    int arr2[n];
    for(i=0;i<n;i++) {
        cin>>arr[i];
        arr2[i]=arr[i];
    }
    for(i=0;i<n;i++) {
        swap(arr[i],arr[arr[i]+1]);
        //cout<<"swap2 "<<arr2[i]<<" "<<arr2[arr2[i]+1]<<endl;
        //swap(arr2[i],arr2[arr2[i]+1]);
        //store both the varibles before giving value
        int temp1=arr2[i];
        int temp2=arr2[arr2[i]+1];
        //arr2[i]=arr2[arr2[i]+1];
        //arr2[arr2[i]+1]=temp;
        //swapping
        arr2[arr2[i]+1]=temp1;
        arr2[i]=temp2;
        /*
           cout<<"after swapping arr"<<endl;
           for(int j=0;j<n;j++) {
           cout<<arr[j]<<" ";
           }
           cout<<endl;
           cout<<"after swapping arr2"<<endl;
           for(int j=0;j<n;j++) {
           cout<<arr2[j]<<" ";
           }
           cout<<endl;
           */
    }
    for(i=0;i<n;i++) {
        cout<<arr[i]<<" ";
    }
    cout<<endl;
    for(i=0;i<n;i++) {
        cout<<arr2[i]<<" ";
    }
}

Input :

$ g++ array.cpp && ./a.out
4
0 1 2 2
1 0 2 2 
1 0 2 2 

Solution 2:[2]

If your goal is to swap every element with the element next to it as you move through the array from 0 to n then all you need is: swap(arr[i], arr[i+1]); You will have to be sure to stop before i+1 is greater than the number of indexes in your array.

if(i+1 >= n) break;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 janst