title: How do you convert variable names to a string in Dart?
body: <p>Very new to Flutter and Dart, so pardon me for the ill-phrased question. </p>
  
  <p>This is a generic code that I have:</p>
  
  <pre><code>// Constructor class
  class ctr {
    String i;
    ctr(String a){
      this.a = a; 
  }
  
  // New variables based on contsructor
  var ctrA = ctr('a');
  var ctrB = ctr('b');
  var ctrC = ctr('c');
  
  // Storing the variables based on constructor in an array
  List ctrList = [ctrA, ctrB, ctrC]
  
  void main() {
    String match = 'ctrB';
    for (var i = 0; i&lt;ctrList.length; i++) {
      if(match == ctrList.toString() {
        print('The string of your match is ${ctrList[i].a}');
      } else {
        print('Error!);
      }
    }
  }
  </code></pre>
  
  <p>The current output is <code>Error!</code>.
  Instead, what I'm looking for is <code>a</code>.</p>
  
  <p>As you can see, I'm trying to iterate the variable <code>match</code> over the array that stores the variables based on an aforementioned constructor, and if it matches, print out the value in the constructor that it has matched to. <code>runtimeType</code> can only get me the name of the origin Class (which will be <code>ctr</code>). </p>
  
  <p>I tried to convert the variable name by using <code>toString()</code> but that didn't work either. What I need is a method to convert these variable names to a string and get a match, but I'm not sure what I can do.</p>
  
  <p>Thanks in advance for the help!</p>