FormatException: Unexpected end of input (at character 1) with OSM map

Viewed 383

I am trying to get all the markers out of my API (it is about 3k points at the same time) and put them on the OSM map. I parsed JSON and put the necessary list in the http-request.I also use a loop inside the widget and try to put all the points I need through the loop and make them appear on the OSM map. But now I got this error:

I/flutter (25693): FormatException: Unexpected end of input (at character 1)
I/flutter (25693): 
I/flutter (25693): ^

My model:

  List<Stop> stopFromJson(String str) => List<Stop>.from(json.decode(str).map((x) => Stop.fromJson(x)));

String stopToJson(List<Stop> data) => json.encode(List<dynamic>.from(data.map((x) => x.toJson())));

class Stop {
  Stop({
    this.stLat,
    this.stLong,
  
  });
  final double stLat;
  final double stLong;

Http-request is:

Future<List<Stop>> fetchStops() async {
  String username = '';
  String password = '';
  String basicAuth =
      'Basic ' + base64Encode(utf8.encode('$username:$password'));
  print(basicAuth);
  final response = await http.get(
      Uri.parse(
          link),
      headers: <String, String>{'authorization': basicAuth});
  var jsonResponse = convert.jsonDecode(response.body) as List;
  return jsonResponse.map((e) => Stop.fromJson(e)).toList();

The loop inside widget where i try to iterate all over the ppints and put them om the map:

@override
  void initState() {
    futureStops = fetchStops();
        super.initState();
  }
  List<Stop> listStops;
  Future<List<Stop>> futureStops;
  List<Marker> allMarkers = [];



  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(),
        body: FutureBuilder(
            future: futureStops,
            builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
              if (snapshot.hasData) {
                listStops = snapshot.data;
               listStops.forEach((Stops) {
                  allMarkers = listStops.map(
                    (e) => Marker(
                      width: 1,
                        height: 1,
                        point: latLong.LatLng(e.stLat, e.stLat),
                        builder: (_) => Icon(
                              Icons.person_pin,
                              color: Colors.green,
                            )),
                  ).toList(growable: true);;
                });

I don't understand what exactly is going wrong, because it seems that I parsed everything correctly and everything should work, but I still get this error. With what it can be connected? Where exactly did I go wrong? I would really appreciate your help.

FIX THIS ISSUE Also it seems to me that the error is somewhere here:

factory Stop.fromJson(Map<String, dynamic> json) => Stop(
    stLat: json["st_lat"],
    stLong: json["st_long"],
1 Answers

Fix it: the issue was about parsing: Should be like that: stLat: json["st_lat"].toDouble(), stLong: json["st_long"].toDouble(), I was pretty sure I did everything correctly, but somehow it didn't parse as I wanted. Now all fixed.

For anyone who will going to take the code of loop from my question: it dosen't work. I will try to solve it and paste here the answer.

Related