Home > Back-end >  Google maps class not getting imported in dart
Google maps class not getting imported in dart

Time:12-11

I am trying to integrate google maps api in my flutter app.

I have used 3 libraries: google_map, dio and flutter_polyline_points from pub.dev

My error is that even after doing "pubspec run", the GoogleMap() class is not getting recognized.

Code:

import 'package:flutter/material.dart';
import 'package:google_maps/google_maps.dart';
import 'package:dio/dio.dart';
import 'package:flutter_polyline_points/flutter_polyline_points.dart';
import 'package:travel/widgets/home_page_sidebar.dart';

class MapsScreen extends StatefulWidget {
  static String id = "MapsScreen";
  @override
  State<StatefulWidget> createState() {
    return MapsScreenState();
  }
}

class MapsScreenState extends State<MapsScreen> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          "Travel"
        ),
      ),
      drawer: Drawer(
        child: HomePageSideBar(),
      ),
      body: GoogleMap()
    );
  }

}

I am getting red line under GoogleMap() in android studio. I have tried restarting the app but it doesn't work.

Why is the class not getting recognized?

CodePudding user response:

A quick look at the docs for the google_maps lib shows it's probably named GMap, not GoogleMap.

Here's the example from their pub.dev docs page:

import 'dart:html';

import 'package:google_maps/google_maps.dart';

void main() {
  final mapOptions = MapOptions()
    ..zoom = 8
    ..center = LatLng(-34.397, 150.644);
  GMap(document.getElementById("map-canvas"), mapOptions);
}

CodePudding user response:

yo utilizo esta lib
https://pub.dev/packages/google_maps_flutter

GoogleMap( mapType: MapType.hybrid, initialCameraPosition: initialPosition, onMapCreated: (GoogleMapController controller) { _controller.complete(controller); }, ),

  • Related