Harsh Bhudolia
Harsh Bhudolia

Reputation: 153

INVALID IMAGE DATA WHILE USING FLUTTER_MAP

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: FutureBuilder(
        future: acquireCurrentLocation(),
        builder: (BuildContext context, AsyncSnapshot<LatLng?> snapshot) {
          if (snapshot.hasData) {
            print(snapshot.data);
            print(snapshot.data!.latitude);
            return FlutterMap(
              options: MapOptions(
                center:
                    LatLng(snapshot.data!.latitude, snapshot.data!.longitude),
                zoom: 13.0,
              ),
              layers: [
                TileLayerOptions(
                    urlTemplate:
                        "cc",
                    additionalOptions: {
                      'accessToken':
                          'cc',
                      'id': 'cc',
                    }),
                MarkerLayerOptions(
                  markers: [
                    Marker(
                      width: 80.0,
                      height: 80.0,
                      point: LatLng(
                          snapshot.data!.latitude, snapshot.data!.longitude),
                      builder: (ctx) => Container(
                        child: IconButton(
                          icon: Icon(Icons.location_on),
                          onPressed: null,
                          color: Colors.red,
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            );
          } else if (!snapshot.hasData) {
            return Center(
              child: CircularProgressIndicator(),
            );
          } else {
            return Container();
          }
        },
      ),
    );
  }
}

I am getting the error Invalid Image Data, I have input the correct token, URL in my working file. Can Someone tell me what I am doing wrong or how I can solve the error? I have tried running it in emulator as well as Real device, the error on debugging was shown in the painter.dart file in the most likely Future function declaration when(error!=null)

Upvotes: 2

Views: 1075

Answers (1)

JaffaKetchup
JaffaKetchup

Reputation: 1628

Instead of exporting as whatever you were doing, try exporting it as 'Carto', and then using that template they give you as the urlTemplate, and the private key as the additionalOptions. This is the format used by flutter_map.

Upvotes: 3

Related Questions