title: Is there a way to have an argument with two types in Dart?
body: <p>For navigation, I built a simple factory class that generates a ListTile that pushes a route to the Navigator:</p>
  
  <pre><code>static Widget simpleNavRow(String text, BuildContext context, String route) {
    return Column(
      children: &lt;Widget&gt;[
        ListTile(
          title: Text(text),
          onTap: () {
            Navigator.pushNamed(context, route);
          },
        ),
        Divider(),
      ],
    );
  }
  </code></pre>
  
  <p>However, I soon realized that it would be convenient to support pushing widgets as well (or instantiate from their class if possible). I couldn't figure out how to make the "route" argument accept either a String or a Widget, so I created a class that initializes with one of those two types. This code works, but is there a better way to achieve this?</p>
  
  <pre><code>class NavTo {
    String route;
    Widget widget;
  
    NavTo.route(this.route);
    NavTo.widget(this.widget);
  
    push(BuildContext context) {
      if (route != null) {
        Navigator.pushNamed(context, route);
      }
      if (widget != null) {
        Navigator.push(context, MaterialPageRoute(builder: (context) {
          return widget;
        }));
      }
    }
  }
  
  class ListHelper {
    static final padding = EdgeInsets.all(12.0);
  
    static Widget simpleNavRow(String text, BuildContext context, NavTo navTo) {
      return Column(
        children: &lt;Widget&gt;[
          ListTile(
            title: Text(text),
            onTap: () {
              navTo.push(context);
            },
          ),
          Divider(),
        ],
      );
    }
  }
  
  // usage:
  // ListHelper.simpleNavRow('MyWidget', context, NavTo.widget(MyWidget()))
  </code></pre>