title: How to create a method with a generic return type in dart
body: <p>I have a enum defined like this</p>
  <pre><code>enum PropertyType { apartment, villa, plot }
  enum PossesionType { readyToMove, underConstruction }
  </code></pre>
  <p>I am trying to create a generic method,which returns me the right enum when given a string as input</p>
  <pre><code>
  class Property&lt;T&gt; {
   T getGenericType(String text) {
      switch (text) {
        case 'Ready to move':
          return PossesionType.readyToMove;
          break;
        case 'Apartment':
          return PropertyType.apartment;
          break;
        ....
        ....
        ....  
        default:
          return PossesionType.readyToMove;
   }   
  }
  
  </code></pre>
  <p>I understand this will throw an error since it expects a return type of T, to get this working without generics I need to write two different functions with a different return type but both functions will basically do the same thing.</p>
  <pre><code>  PropertyType getSelectedProperty(String text) {
      switch (text) {
        case 'Apartment':
          return PropertyType.apartment;
          break;
        case 'Villa':
          return PropertyType.villa;
          break;
        case 'Plot':
          return PropertyType.plot;
          break;
        default:
          return PropertyType.apartment;
      }
    }
  
    PossesionType getSelectedPossession(String text) {
      switch (text) {
        case 'Ready to move':
          return PossesionType.readyToMove;
          break;
        case 'Under Construction':
          return PossesionType.underConstruction;
          break;
        default:
          return PossesionType.readyToMove;
      }
    }
  </code></pre>
  <p>I am new to generics so can someone help me understand how can I achieve this.</p>