2

I have a problem in intergrating a simple GoogleMap in my Flutter App. I correctly inserted the API Key in my Manifest file and inserted the library in the app. But the emulator is just showing a blank page. I am doing nothing special until now; just trying to create a GoogleMap.

This is the Code i am using in the App:

return Stack(
 children: <Widget>[
   GoogleMap(initialCameraPosition: CameraPosition(target:
   LatLng(-33.870840,151.206286),
   zoom: 12)
   )
 ], );

What the emulator is showing:

enter image description here

The first lines in the console(which i think are of special meaning):

E/flutter ( 5736): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: plugins.flutter.io/google_maps

I tried several workarounds but only ended up with more errors. Looking Forward to your answers!

Dee Jott
  • 125
  • 1
  • 2
  • 12

1 Answers1

4

I tried to add Google Map in a fresh project and was able to see it on emulator successfully. I followed this article step by step and used your code snippet to show the map and it worked.

Complete code used:

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  Completer<GoogleMapController> _controller = Completer();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Maps Sample App'),
          backgroundColor: Colors.green[700],
        ),
        body: Stack(
      children: <Widget>[
      GoogleMap(initialCameraPosition: CameraPosition(target:
      LatLng(-33.870840,151.206286),
        zoom: 12)
    )
    ],
        )
      ),
    );
  }
}

enter image description here

Couple of points to note:

  1. Double check if the api is enabled (Maps SDK for Android) when you generated key for it.
  2. Do flutter clean once you cross-check to confirm you've latest dependencies.

Hope this helps.

Darshan
  • 10,550
  • 5
  • 49
  • 61
  • 2
    Thank you, its working now! Dont exactly know what was wrong but i think it was the fact that i didnt wrote the whole number for the package version in my pubspec file(Just had 0.5.21 instead of 0.5.21+15). Also used Flutter Clean so maybe that hepled me with the rest. – Dee Jott Dec 18 '19 at 08:27