flutter_animarker 3.1.1+2-alpha copy "flutter_animarker: ^3.1.1+2-alpha" to clipboard
flutter_animarker: ^3.1.1+2-alpha copied to clipboard

Solution to move a Marker smoothly throught Google Maps in Flutter.

example/lib/main.dart

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_animarker/flutter_map_marker_animation.dart';
import 'package:flutter_map_marker_animation_example/listen_locations_updates.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

//Setting dummies values
const kStartPosition = LatLng(18.488213, -69.959186);
const kSantoDomingo = CameraPosition(target: kStartPosition, zoom: 15);
const kMarkerId = MarkerId('MarkerId1');
const kDuration = Duration(seconds: 4);
const kLocations = [
  kStartPosition,
  LatLng(18.488101, -69.957995),
  LatLng(18.489210, -69.952459),
  LatLng(18.487307, -69.952759)
];

class SimpleMarkerAnimationExample extends StatefulWidget {
  @override
  SimpleMarkerAnimationExampleState createState() => SimpleMarkerAnimationExampleState();
}

class SimpleMarkerAnimationExampleState extends State<SimpleMarkerAnimationExample> {
  final markers = <MarkerId, Marker>{};
  final controller = Completer<GoogleMapController>();
  final stream = Stream.periodic(kDuration, (count) => kLocations[count]).take(kLocations.length);

  @override
  void initState() {
    stream.forEach((value) => newLocationUpdate(value));

    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Google Maps Markers Animation Example',
      home: Animarker(
        curve: Curves.bounceOut,
        rippleRadius: 0.2,
        duration: Duration(milliseconds: 2300),
        mapId: controller.future.then<int>((value) => value.mapId), //Grab Google Map Id
        markers: markers.values.toSet(),
        child: GoogleMap(
          mapType: MapType.normal,
          initialCameraPosition: kSantoDomingo,
          onMapCreated: (gController) =>
              controller.complete(gController), //Complete the future GoogleMapController
        ),
      ),
    );
  }

  void newLocationUpdate(LatLng latLng) {
    var marker = RippleMarker(
      markerId: kMarkerId,
      position: latLng,
      ripple: true,
    );
    setState(() => markers[kMarkerId] = marker);
  }
}

void main() {
  runApp(FlutterMapMarkerAnimationRealTimeExample());
}
160
likes
120
points
14.2k
downloads

Publisher

verified publishergaurisjavier.com

Weekly Downloads

Solution to move a Marker smoothly throught Google Maps in Flutter.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

flutter, google_maps_flutter_platform_interface, vector_math

More

Packages that depend on flutter_animarker