Coder Social home page Coder Social logo

rithik-dev / google_maps_widget Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 9.0 229 KB

A Flutter package which can be used to make polylines(route) from a source to a destination, and also handle a driver's realtime location (if any) on the map.

Home Page: https://pub.dev/packages/google_maps_widget

License: MIT License

Dart 91.37% Java 0.42% Objective-C 2.39% Kotlin 0.34% Swift 1.11% HTML 4.36%
dart flutter android ios flutter-package polylines driver markers pub package

google_maps_widget's Introduction

GoogleMapsWidget For Flutter

pub package likes popularity pub points

A widget for flutter developers to easily integrate google maps in their apps. It can be used to make polylines from a source to a destination, and also handle a driver's realtime location (if any) on the map.

Features

  • Make polylines (route) between two locations by providing the latitude and longitude for both the locations.
  • The route is customizable in terms of color and width.
  • The plugin also offers realtime location tracking for a driver(if any) and shows a marker on the map which updates everytimes the driver's location changes.
  • All the markers are customizable.
  • onTap callbacks are implemented for all the markers and their info windows to easily handle user interaction.
  • Almost all the parameters defined in google_maps_flutter for the GoogleMap widget can be passed as arguments to the widget.

Screenshots

      

Getting Started

  • Get an API key at https://cloud.google.com/maps-platform/.

  • Enable Google Map SDK for each platform.

    • Go to Google Developers Console.
    • Choose the project that you want to enable Google Maps on.
    • Select the navigation menu and then select "Google Maps".
    • Select "APIs" under the Google Maps menu.
    • To enable Google Maps for Android, select "Maps SDK for Android" in the "Additional APIs" section, then select "ENABLE".
    • To enable Google Maps for iOS, select "Maps SDK for iOS" in the "Additional APIs" section, then select "ENABLE".
    • To enable Directions API, select "Directions API" in the "Additional APIs" section, then select "ENABLE".
    • Make sure the APIs you enabled are under the "Enabled APIs" section.

For more details, see Getting started with Google Maps Platform.

Android

Specify your API key in the application manifest android/app/src/main/AndroidManifest.xml:

<manifest ...
  <application ...
    <meta-data android:name="com.google.android.geo.API_KEY"
               android:value="YOUR KEY HERE"/>

iOS

Specify your API key in the application delegate ios/Runner/AppDelegate.m:

#include "AppDelegate.h"
#include "GeneratedPluginRegistrant.h"
#import "GoogleMaps/GoogleMaps.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application
    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [GMSServices provideAPIKey:@"YOUR KEY HERE"];
  [GeneratedPluginRegistrant registerWithRegistry:self];
  return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end

Or in your swift code, specify your API key in the application delegate ios/Runner/AppDelegate.swift:

import UIKit
import Flutter
import GoogleMaps

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GMSServices.provideAPIKey("YOUR KEY HERE")
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }
}

Web (This package is a wrapper around the google_maps_flutter package. If that package supports web, this package will also support web.)

Modify web/index.html

Get an API Key for Google Maps JavaScript API. Get started here. Modify the <head> tag of your web/index.html to load the Google Maps JavaScript API, like so:

<head>

  <!-- // Other stuff -->

  <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_KEY_HERE"></script>
</head>

Usage

To use this plugin, add google_maps_widget as a dependency in your pubspec.yaml file.

  dependencies:
    flutter:
      sdk: flutter
    google_maps_widget:

First and foremost, import the widget.

import 'package:google_maps_widget/google_maps_widget.dart';

You can now add a GoogleMapsWidget widget to your widget tree and pass all the required parameters to get started. This widget will create a route between the source and the destination LatLng's provided.

GoogleMapsWidget(
    apiKey: "YOUR KEY HERE",
    sourceLatLng: LatLng(40.484000837597925, -3.369978368282318),
    destinationLatLng: LatLng(40.48017307700204, -3.3618026599287987),
),

One can create a controller and interact with the google maps controller, or update the source and destination LatLng's.

// can create a controller, and call methods to update source loc,
// destination loc, interact with the google maps controller to
// show/hide markers programmatically etc.
final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();

Pass this controller to the key param in GoogleMapsWidget widget, and then

// call like this to update source or destination, this will also rebuild the route.
mapsWidgetController.currentState!.setSourceLatLng(
  LatLng(
    40.484000837597925 * (Random().nextDouble()),
    -3.369978368282318,
  ),
);

// or, can interact with the google maps controller directly to focus on a marker etc..

final googleMapsCon = await mapsWidgetController.currentState!.getGoogleMapsController();
googleMapsCon.showMarkerInfoWindow(MarkerIconInfo.sourceMarkerId);

Sample Usage

import 'dart:math';

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

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // can create a controller, and call methods to update source loc,
  // destination loc, interact with the google maps controller to
  // show/hide markers programmatically etc.
  final mapsWidgetController = GlobalKey<GoogleMapsWidgetState>();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: SafeArea(
        child: Scaffold(
          body: Column(
            children: [
              Expanded(
                child: GoogleMapsWidget(
                  apiKey: "YOUR GOOGLE MAPS API KEY HERE",
                  key: mapsWidgetController,
                  sourceLatLng: LatLng(
                    40.484000837597925,
                    -3.369978368282318,
                  ),
                  destinationLatLng: LatLng(
                    40.48017307700204,
                    -3.3618026599287987,
                  ),

                  ///////////////////////////////////////////////////////
                  //////////////    OPTIONAL PARAMETERS    //////////////
                  ///////////////////////////////////////////////////////

                  routeWidth: 2,
                  sourceMarkerIconInfo: MarkerIconInfo(
                    infoWindowTitle: "This is source name",
                    onTapInfoWindow: (_) {
                      print("Tapped on source info window");
                    },
                    assetPath: "assets/images/house-marker-icon.png",
                  ),
                  destinationMarkerIconInfo: MarkerIconInfo(
                    assetPath: "assets/images/restaurant-marker-icon.png",
                  ),
                  driverMarkerIconInfo: MarkerIconInfo(
                    infoWindowTitle: "Alex",
                    assetPath: "assets/images/driver-marker-icon.png",
                    onTapMarker: (currentLocation) {
                      print("Driver is currently at $currentLocation");
                    },
                    assetMarkerSize: Size.square(125),
                    rotation: 90,
                  ),
                  updatePolylinesOnDriverLocUpdate: true,
                  onPolylineUpdate: (_) {
                    print("Polyline updated");
                  },
                  // mock stream
                  driverCoordinatesStream: Stream.periodic(
                    Duration(milliseconds: 500),
                    (i) => LatLng(
                      40.47747872288886 + i / 10000,
                      -3.368043154478073 - i / 10000,
                    ),
                  ),
                  totalTimeCallback: (time) => print(time),
                  totalDistanceCallback: (distance) => print(distance),
                ),
              ),
              // demonstrates how to interact with the controller
              Padding(
                padding: const EdgeInsets.all(10),
                child: Row(
                  children: [
                    Expanded(
                      child: ElevatedButton(
                        onPressed: () {
                          mapsWidgetController.currentState!.setSourceLatLng(
                            LatLng(
                              40.484000837597925 * (Random().nextDouble()),
                              -3.369978368282318,
                            ),
                          );
                        },
                        child: Text('Update source'),
                      ),
                    ),
                    const SizedBox(width: 10),
                    Expanded(
                      child: ElevatedButton(
                        onPressed: () async {
                          final googleMapsCon = await mapsWidgetController
                              .currentState!
                              .getGoogleMapsController();
                          googleMapsCon.showMarkerInfoWindow(
                            MarkerIconInfo.sourceMarkerId,
                          );
                        },
                        child: Text('Show source info'),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

See the example directory for a complete sample app.

Created & Maintained By Rithik Bhandari

google_maps_widget's People

Contributors

rithik-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

google_maps_widget's Issues

Why another `apiKey` inside the flutter app?

Hello,

thank for this awesome plugin. It simplified my workflow and made me gain some time. Now I just don't understand why I need to add a key inside the dart code, when I already added it inside the android manifest and iOS Runner App, and also the web?

Platform Exception

Hi,
FIrst, really nice library.
I have an error wile trying to paint a polyline route between 2 points.

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view.  Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions., null, com.google.maps.api.android.lib6.common.apiexception.c: Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view.  Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions.

I have a list of maps to show different trips.

My parameters are:

                       sourceLatLng: LatLng(originLatitude!, originLongitude!),
                        destinationLatLng:
                            LatLng(destinationLatitude!, destinationLongitude!),
                        routeColor: AppColors.primaryColor,
                        scrollGesturesEnabled: true,
                        rotateGesturesEnabled: true,
                        routeWidth: 1,
                        zoomGesturesEnabled: true,
                        showPolyline: true,
                        zoomControlsEnabled: true,

Runnig last version of google maps flutter and flutter 3.2

Ability to Rotate car to Path Direction

Hello,
I am trying to implement a tracker service and I want the car marker to point towards the road it headed to. Upon doing some research I would want the rotate parameter in the Marker for at least driverMarkerIconInfo unless you recommend any other way?
Thanks

Regarding driverCoordinatesStream

Hello,
I have an api call that returns me back latitude and longitude.
I want to make that call every second and then pass it in driverCoordinatesStream and make the vehicle move
Can you help me how to do that?
I am using bloc but if you are not familiar with it you can just help with directly call as well

    
  driverCoordinatesStream: Stream.periodic(
                            Duration(seconds: 1),
                            (_) {
                              double? lat;
                              double? long;
// Making API call 
                              BlocProvider.of<RsaTrackerCubit>(context).getTowTruckTrackingLocationInfo();
// if successful update latitude longitude
                              if (state is RsaTowTruckLocationSuccessfullState && lat != null && long != null) {
                                lat = state.towTruckTrackingResponse?.job?.partner?.vehicle?.location?.lat?.toDouble();
                                long = state.towTruckTrackingResponse?.job?.partner?.vehicle?.location?.long?.toDouble();
// if unsuccessful use the last successful value
                              } else {
                                lat = lat;
                                long = long;
                              }

                              return LatLng(
                                lat ?? 35.957819,
                                long ?? -81.998999,
                              );
                            },
                          ),


Please let me know if its possible or not or if any other alternatives

error when closing or exiting the map

Hello, how are you? every time you try to exit or close the map it gives this error

`I/flutter (25140): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (25140): The following assertion was thrown while finalizing the widget tree:
I/flutter (25140): 'package:flutter/src/widgets/framework.dart': Failed assertion: line 4276 pos 12: '_lifecycleState
I/flutter (25140): != _ElementLifecycle.defunct': is not true.
I/flutter (25140):
I/flutter (25140): Either the assertion indicates an error in the framework itself, or we should provide substantially
I/flutter (25140): more information in this error message to help you determine and fix the underlying cause.
I/flutter (25140): In either case, please report this assertion by filing a bug on GitHub:
I/flutter (25140): https://github.com/flutter/flutter/issues/new?template=2_bug.md
I/flutter (25140):
I/flutter (25140): When the exception was thrown, this was the stack:
I/flutter (25140): #2 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4276:12)
I/flutter (25140): #3 State.setState (package:flutter/src/widgets/framework.dart:1108:15)
I/flutter (25140): #4 MapsService.clear (package:google_maps_widget/src/services/maps_service.dart:365:14)
I/flutter (25140): #5 _GoogleMapsWidgetState.dispose (package:google_maps_widget/src/main_widget.dart:387:18)
I/flutter (25140): #6 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4895:11)
I/flutter (25140): #7 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1883:13)
I/flutter (25140): #8 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #9 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6297:16)
I/flutter (25140): #10 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #11 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #12 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #13 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #14 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #15 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #16 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #17 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #18 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #19 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #20 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #21 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6297:16)
I/flutter (25140): #22 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #23 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #24 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #25 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #26 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #27 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #28 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #29 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #30 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #31 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #32 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #33 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #34 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #35 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #36 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #37 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #38 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #39 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #40 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #41 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #42 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #43 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #44 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #45 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #46 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #47 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #48 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #49 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #50 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #51 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #52 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #53 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #54 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #55 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #56 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #57 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #58 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #59 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #60 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #61 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #62 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #63 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #64 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #65 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #66 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #67 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #68 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #69 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #70 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #71 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #72 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #73 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #74 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #75 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #76 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #77 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #78 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #79 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #80 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #81 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #82 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #83 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #84 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #85 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #86 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #87 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #88 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #89 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #90 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #91 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #92 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #93 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #94 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #95 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #96 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #97 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #98 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #99 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #100 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #101 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #102 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #103 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #104 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #105 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #106 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #107 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #108 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #109 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #110 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #111 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #112 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #113 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #114 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #115 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #116 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #117 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #118 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #119 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #120 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #121 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #122 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #123 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)

======== Exception caught by widgets library =======================================================
The following assertion was thrown while finalizing the widget tree:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 4276 pos 12: '_lifecycleState != _ElementLifecycle.defunct': is not true.

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack:
#2 Element.markNeedsBuild (package:flutter/src/widgets/framework.dart:4276:12)
#3 State.setState (package:flutter/src/widgets/framework.dart:1108:15)
#4 MapsService.clear (package:google_maps_widget/src/services/maps_service.dart:365:14)
#5 _GoogleMapsWidgetState.dispose (package:google_maps_widget/src/main_widget.dart:387:18)
#6 StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4895:11)
#7 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1883:13)
#8 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#9 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6297:16)
#10 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#11 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#12 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#13 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#14 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#15 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#16 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#17 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#18 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#19 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#20 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#21 MultiChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6297:16)
#22 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#23 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#24 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#25 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#26 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#27 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#28 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#29 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#30 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#31 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#32 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#33 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#34 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#35 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#36 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#37 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#38 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#39 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#40 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#41 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#42 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#43 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#44 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#45 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#46 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#47 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#48 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#49 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#50 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#51 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#52 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#53 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#54 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#55 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#56 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#57 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#58 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#59 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#60 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#61 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#62 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#63 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#64 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#65 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#66 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#67 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#68 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#69 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#70 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#71 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#72 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#73 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#74 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#75 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#76 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#77 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#78 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#79 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#80 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#81 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#82 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#83 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#84 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#85 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#86 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#87 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#88 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#89 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#90 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#91 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#92 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#93 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#94 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#95 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#96 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#97 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#98 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#99 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#100 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#101 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#102 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#103 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#104 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#105 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#106 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#107 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#108 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#109 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#110 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#111 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#112 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#113 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#114 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#115 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#116 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#117 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#118 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#119 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#120 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#121 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#122 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#123 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#124 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#125 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#126 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#127 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#128 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#129 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#130 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#131 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#132 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#133 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#134 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#135 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#136 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#137 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#138 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#139 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#140 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#141 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#142 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#143 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#144 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#145 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#146 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#147 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
#148 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#149 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#150 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#151 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#152 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#153 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#154 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#155 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
#156 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
#157 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
#158 ListIterable.forEach (dart:_internal/iterable.dart:39:13)
#159 _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1892:25)
#160 BuildOwner.finalizeTree. (package:flutter/src/widgets/framework.dart:2879:27)
#161 BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2510:15)
#162 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2878:7)
#163 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884:19)
#164 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
#165 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
#166 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
#167 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
#171 _invoke (dart:ui/hooks.dart:166:10)
#172 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
#173 _drawFrame (dart:ui/hooks.dart:129:31)
(elided 5 frames from class _AssertionError and dart:async)

I/flutter (25140): #124 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #125 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #126 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #127 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #128 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #129 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #130 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #131 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #132 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #133 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #134 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #135 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #136 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #137 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #138 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #139 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #140 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #141 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #142 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #143 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #144 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #145 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #146 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #147 SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:6182:14)
I/flutter (25140): #148 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #149 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #150 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #151 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #152 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #153 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #154 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #155 _InactiveElements._unmount. (package:flutter/src/widgets/framework.dart:1881:7)
I/flutter (25140): #156 ComponentElement.visitChildren (package:flutter/src/widgets/framework.dart:4719:14)
I/flutter (25140): #157 _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:1879:13)
I/flutter (25140): #158 ListIterable.forEach (dart:_internal/iterable.dart:39:13)
I/flutter (25140): #159 _InactiveElements._unmountAll (package:flutter/src/widgets/framework.dart:1892:25)
I/flutter (25140): #160 BuildOwner.finalizeTree. (package:flutter/src/widgets/framework.dart:2879:27)
I/flutter (25140): #161 BuildOwner.lockState (package:flutter/src/widgets/framework.dart:2510:15)
I/flutter (25140): #162 BuildOwner.finalizeTree (package:flutter/src/widgets/framework.dart:2878:7)
I/flutter (25140): #163 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:884:19)
I/flutter (25140): #164 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:319:5)
I/flutter (25140): #165 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1143:15)
I/flutter (25140): #166 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1080:9)
I/flutter (25140): #167 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:996:5)
I/flutter (25140): #171 _invoke (dart:ui/hooks.dart:166:10)
I/flutter (25140): #172 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:270:5)
I/flutter (25140): #173 _drawFrame (dart:ui/hooks.dart:129:31)
I/flutter (25140): (elided 5 frames from class _AssertionError and dart:async)
I/flutter (25140): ════════════════════════════════════════════════════════════════════════════════════════════════════
`

Help Needed - is it possible to show info windows on all markers by default?

Hi @rithik-dev ,

Since you know more about the google maps package, may I ask is it possible to show infoWindow for all markers by default?

I tried below that is looping through markers and showInfoWindow but that shows only the last marker's info window.

Thank you very much for your help.

this is how I try:

// // Show the info windows for all markers
    for (final marker in _markers) {
      print(marker.infoWindow.title);
      await Future.delayed(const Duration(milliseconds: 300));
      _googleMapController.showMarkerInfoWindow(marker.markerId);
     
    }

my full code is below:

import 'dart:async';
import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:ugv_fe/api/backend_api.dart';
import 'package:ugv_fe/models/vehicle2.dart';
import 'package:ugv_fe/pages/vehicles_list.dart';
import 'package:ugv_fe/provider/theme_provider.dart';

class LandingPage extends StatefulWidget {
  const LandingPage({Key? key}) : super(key: key);

  @override
  State<LandingPage> createState() => _LandingPageState();
}

class _LandingPageState extends State<LandingPage> {
  Timer? _timer;
  bool _isPageOpen = true;

  int selectedVehicleIndex = 0;
  static LatLng current_Camera_posistion = const LatLng(0, 0);
  String? _mapStyle;
  late GoogleMapController _googleMapController;
  static List<Vehicle> allVehiclesList = [];
  bool showVehiclesList = false;
  bool markersLoading = false;
  bool vehiclesLoaded = false;
  // final Map<String, Marker> _markers = {};
  final List<Marker> _markers = [];
  int markerFlag = -1;
  // final Set<Marker>? _markers = <Marker>{};
  BitmapDescriptor? activeMarker;
  BitmapDescriptor? offlineMarker;
  BitmapDescriptor? alertMarker;
  BitmapDescriptor? activeMarkerSelected;
  BitmapDescriptor? offlineMarkerSelected;
  BitmapDescriptor? alertMarkerSelected;

  Future<BitmapDescriptor> getIcon(
      {required String imagePath, required int width}) async {
    final Uint8List markerIcon = await getBytesFromAsset(imagePath, width);
    BitmapDescriptor icon = BitmapDescriptor.fromBytes(markerIcon);
    return icon;
  }

  Future<Uint8List> getBytesFromAsset(String path, int width) async {
    ByteData data = await rootBundle.load(path);
    Codec codec = await instantiateImageCodec(data.buffer.asUint8List(),
        targetWidth: width);
    FrameInfo fi = await codec.getNextFrame();
    return (await fi.image.toByteData(format: ImageByteFormat.png))!
        .buffer
        .asUint8List();
  }

  Future<void> setMarkerIcon() async {
    print("Trying to setup Marker");
    print(markersLoading);
    activeMarker =
        await getIcon(imagePath: 'assets/images/marker_online.png', width: 100);
    activeMarkerSelected =
        await getIcon(imagePath: 'assets/images/marker_online.png', width: 130);
 
    offlineMarker = await getIcon(
        imagePath: 'assets/images/marker_offline.png', width: 100);
    offlineMarkerSelected = await getIcon(
        imagePath: 'assets/images/marker_offline.png', width: 130);
  
    alertMarker =
        await getIcon(imagePath: 'assets/images/marker_alert.png', width: 100);
    alertMarkerSelected =
        await getIcon(imagePath: 'assets/images/marker_alert.png', width: 130);

    setState(() {
      markersLoading = true;
    });
  }

  static final CameraPosition _kGooglePlex = CameraPosition(

    target: LatLng(double.tryParse(allVehiclesList[0].vehicleLatitude!) ?? 0.0,
        double.tryParse(allVehiclesList[0].vehicleLongitude!) ?? 0.0),
    zoom: 18,
  );

  Future<void> _onMapCreated(GoogleMapController controller) async {

    _googleMapController = controller;
    setState(() {
      _markers.clear();
      print("VehiclesList inside onMapCreated");
      print(allVehiclesList);
      var cnt = 0;
      for (final vehicle in allVehiclesList) {
        int idMarker = cnt;
        _markers.add(Marker(
          consumeTapEvents: true,
          icon: (vehicle.vehicleIsOnline! &&
                  vehicle.vehicleCurrentStatus == 'Active')
              ? activeMarker!
              : (vehicle.vehicleCurrentStatus == 'Alert')
                  ? alertMarker!
                  : offlineMarker!,
          markerId: MarkerId(idMarker.toString()),
          position: LatLng(double.tryParse(vehicle.vehicleLatitude!)!,
              double.tryParse(vehicle.vehicleLongitude!)!),
          infoWindow: InfoWindow(
            title: vehicle.vehicleName,
       
          ),
          onTap: () {
            if (markerFlag != idMarker) {
              setState(() {
                // resetMarkers();

                if (markerFlag != -1) {
                  Vehicle oldSelectedVehicle = allVehiclesList[markerFlag];
                  _markers[markerFlag] = _markers[markerFlag].copyWith(
                    iconParam: (oldSelectedVehicle.vehicleIsOnline! &&
                            oldSelectedVehicle.vehicleCurrentStatus == 'Active')
                        ? activeMarker!
                        : (oldSelectedVehicle.vehicleCurrentStatus == 'Alert')
                            ? alertMarker!
                            : offlineMarker!,
                  );
                }
                _markers[idMarker] = _markers[idMarker].copyWith(
                  iconParam: (vehicle.vehicleIsOnline! &&
                          vehicle.vehicleCurrentStatus == 'Active')
                      ? activeMarkerSelected!
                      : (vehicle.vehicleCurrentStatus == 'Alert')
                          ? alertMarkerSelected!
                          : offlineMarkerSelected!,
                );
                markerFlag = idMarker;
              });
            }
            showVehiclesListPopup(idMarker);
          },
        ));
        // _googleMapController
        //     .showMarkerInfoWindow(MarkerId(idMarker.toString()));
        // _markers[vehicle.vehicleName] = marker;
        cnt += 1;
      }
    });
    // // Show the info windows for all markers
    for (final marker in _markers) {
      print(marker.infoWindow.title);
      await Future.delayed(const Duration(milliseconds: 300));
      _googleMapController.showMarkerInfoWindow(marker.markerId);
     
    }
  }

  getData() async {
    var result = await CallApi().getVehicles();
    allVehiclesList = result;
    print("Inside Get Data");
    print(allVehiclesList);
    for (final vehicle in allVehiclesList) {
      print(vehicle.vehicleName);
    }
    setState(() {
      vehiclesLoaded = true;
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
    setMarkerIcon();
    rootBundle.loadString('assets/map_style.txt').then((string) {
      _mapStyle = string;
    });
    _timer = Timer.periodic(const Duration(seconds: 30), (Timer t) {
      if (_isPageOpen) {
        reloadGetData();
      } else {
        _timer?.cancel();
      }
    });
  }

  @override
  void dispose() {
    _isPageOpen = false;
    _timer?.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: <Widget>[
        !markersLoading || !vehiclesLoaded
            ? const SpinKitWave(size: 32, color: AppThemes.appCommonRedColor)
            : GoogleMap(
                onTap: (value) {
                  setState(() {
                 
                    markerFlag = -1;
                  });
                },
                mapType: MapType.hybrid,
                onMapCreated: _onMapCreated,
                initialCameraPosition: _kGooglePlex,
                markers: _markers.toSet(),
                mapToolbarEnabled: false,
                zoomControlsEnabled: false,
                padding: const EdgeInsets.all(150),
                onCameraMove: (CameraPosition position) {
                  setState(() {
                    current_Camera_posistion = LatLng(
                        position.target.latitude, position.target.longitude);
                  });
                },
              ),

        Positioned(
          top: 20,
          left: 5,
          child: Card(
            elevation: 20,
            child: SizedBox(
              // color: const Color(0xFFFAFAFA),
              width: 40,
              height: 100,
              child: Column(
                children: <Widget>[
                  IconButton(
                      icon: const Icon(Icons.add),
                      onPressed: () async {
                        var currentZoomLevel =
                            await _googleMapController.getZoomLevel();
                        print(currentZoomLevel);

                        currentZoomLevel = currentZoomLevel + 2;
                        _googleMapController.animateCamera(
                          CameraUpdate.newCameraPosition(
                            CameraPosition(
                              target: current_Camera_posistion,
                              zoom: currentZoomLevel,
                            ),
                          ),
                        );
                      }),
                  const SizedBox(height: 2),
                  IconButton(
                      icon: const Icon(Icons.remove),
                      onPressed: () async {
                        var currentZoomLevel =
                            await _googleMapController.getZoomLevel();
                        print(currentZoomLevel);
                        currentZoomLevel = currentZoomLevel - 2;
                        if (currentZoomLevel < 0) currentZoomLevel = 0;
                        _googleMapController.animateCamera(
                          CameraUpdate.newCameraPosition(
                            CameraPosition(
                              target: current_Camera_posistion,
                              zoom: currentZoomLevel,
                            ),
                          ),
                        );
                      }),
                ],
              ),
            ),
          ),
        ),
        // Positioned(
        //     top: 20,
        //     right: 5,
        //     child: FloatingActionButton(
        //         mini: true,
        //         backgroundColor: AppThemes.appCommonBGColor,
        //         child: const Icon(Icons.refresh_rounded),
        //         onPressed: () {
        //           print('Pressed reload');
        //           reloadGetData();
        //         })),
        showVehiclesList
            ? Positioned(
                right: 10,
                bottom: MediaQuery.of(context).size.height * 0.5 + 62,
                child: FloatingActionButton(
                    child: const Icon(
                      Icons.close,
                      color: AppThemes.appCommonRedColor,
                    ),
                    backgroundColor:
                        Theme.of(context).colorScheme.surface.withOpacity(0.7),
                    mini: true,
                    onPressed: hideVehiclesListPopup),
              )
            : const SizedBox.shrink(),
        showVehiclesList
            ? Positioned(
                left: 10,
                right: 10,
                bottom: 58,
                child: VehiclesList(
                  vehiclesList: allVehiclesList,
                  selectedVehicleIndex: selectedVehicleIndex,
                ))
            : const SizedBox.shrink(),
      ],
    );
  }

  showVehiclesListPopup(int index) {
    setState(() {
      showVehiclesList = true;
      selectedVehicleIndex = index;
      // print("I am here");
      // print(vehicleId);

      // selectedVehicleIndex = allVehiclesList
      //     .indexWhere((vehicle) => vehicle.vehicleId == vehicleId);
      // print(selectedVehicleIndex);
    });
  }

  hideVehiclesListPopup() {
    setState(() {
      showVehiclesList = false;
    });
  }

  resetMarkers() {
    var index = 0;
    setState(() {
      for (final vehicle in allVehiclesList) {
        print(vehicle.vehicleId);
        _markers[index] = _markers[index].copyWith(
          iconParam: (vehicle.vehicleIsOnline! &&
                  vehicle.vehicleCurrentStatus == 'Active')
              ? activeMarker!
              : (vehicle.vehicleCurrentStatus == 'Alert')
                  ? alertMarker!
                  : offlineMarker!,
        );
      }
    });
  }

  Future<void> reloadGetData() async {
    await getData();
    await setMarkerIcon();
    await _onMapCreated(_googleMapController);
    print('Data Reloaded Landing Page');
    setState(() {
      // Your code here
    });
  }
}

Dynamic polylines

Hello,
I want the polylines to be generated on the map dynamically based on drivers position and a fixed destination. So basically as driver moves closer to destination previous lines disappear as it has a new source location
I am getting stream of driver latitude and longitude from the api. How do I set a dynamic source location or what is the best possible way to handle this?
Thanks

Does this Widget work for web?

When I try to compile for web, I simply get "TargetPlatform is not yet supported" in place of the map when I visit the web page.

I have added the link with my API key inside web/index.html as it says in the README.

On pub.dev it says that web is supported by this plugin. What's the status?

custom info window

Hi, can you please add to option InfoWindow, because I have custom info window

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.