title: Map Json with dart
body: <p>I'm trying to make a simple server app with dart. It should take an id and print the associated name. For example if i enter the url "<a href="http://localhost:4040/?id=12" rel="nofollow noreferrer">http://localhost:4040/?id=12</a>" in my browser I want "Heroname: Narco" to printed at the page.</p>
  
  <p>This is the content of the file heros:</p>
  
  <pre><code>{'id': 11, 'name': 'Mr. Nice'}
  {'id': 12, 'name': 'Narco'}
  {'id': 13, 'name': 'Bombasto'}
  {'id': 14, 'name': 'Celeritas'}
  {'id': 15, 'name': 'Magneta'}
  {'id': 16, 'name': 'RubberMan'}
  {'id': 17, 'name': 'Dynama'}
  {'id': 18, 'name': 'Dr IQ'}
  {'id': 19, 'name': 'Magma'}
  {'id': 20, 'name': 'Tornado'}
  </code></pre>
  
  <p>hero.dart</p>
  
  <pre><code>class Hero {
    final int id;
    String name;
    Hero(this.id, this.name);
  
    factory Hero.fromJson(Map&lt;String, dynamic&gt; hero) =&gt;
        Hero(_toInt(hero['id']), hero['name']);
  
    Map toJson() =&gt; {'id': id, 'name': name};
  
  }
  
  int _toInt(id) =&gt; id is int ? id : int.parse(id);
  </code></pre>
  
  <p>hero_dart_service.dart</p>
  
  <pre><code>import 'dart:io';
  import 'dart:async';
  import 'dart:convert';
  
  import '../angular_tour_of_heroes/lib/src//hero.dart';
  
  String _host = InternetAddress.loopbackIPv4.host;
  String path = 'heros';
  List&lt;Hero&gt; heros = new List();
  var list;
  
  void main() async{
    list = await getData();
    var server = await HttpServer.bind(InternetAddress.loopbackIPv4, 4040);
    print('Listening on localhost:${server.port}');
  
    await for (var request in server) {
      handleRequest(request);
    }
  
  }
  
  Future&lt;List&lt;String&gt;&gt; getData() async{
    List&lt;String&gt; list = new List();
    Stream lines = new     File(path).openRead().transform(utf8.decoder).transform(const LineSplitter());
    try {
        await for (var line in lines) {
          list.add(line);
        }
    } catch(e) {
        print(e);
        throw new Exception(e);
    }
    return list;
  }
  
  void handleRequest(HttpRequest request) {
    try {
      if (request.method == 'GET') {
        handleGet(request);
      } else {
        request.response
          ..statusCode = HttpStatus.METHOD_NOT_ALLOWED
          ..write('Unsupported request: ${request.method}.')
          ..close();
      }
    } catch (e) {
      print('Unsupported request: $e');
    }
  }
  
  handleGet(HttpRequest request) {
    heros = list.map((json) =&gt; Hero.fromJson(json)).toList();
    final id = request.uri.queryParameters['id'];
    var targetHero = heros.where((hero) =&gt; hero.id == id);
    var name = targetHero;//.name;
    final response = request.response;
    response.statusCode = HttpStatus.OK;
    response
      ..write('Heroname: $name')
      ..close();
  }
  </code></pre>
  
  <p>When I launch the app, there's no error, but when I enter an url like "<a href="http://localhost:4040/?id=12" rel="nofollow noreferrer">http://localhost:4040/?id=12</a>" in the browser, I get this error message "Unsupported request: type 'String' is not a subtype of type 'Map".</p>
  
  <p>I don't no why this doesn't work. Can anybody give me a hint?</p>