Skip to content
This repository was archived by the owner on Jul 11, 2021. It is now read-only.

Commit 04ce63d

Browse files
committed
FAB position via options; adds animated map movement
1 parent 8c16630 commit 04ce63d

File tree

103 files changed

+96
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+96
-39
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

100644100755
File mode changed.

.github/ISSUE_TEMPLATE/feature_request.md

100644100755
File mode changed.

.gitignore

100644100755
File mode changed.

.metadata

100644100755
File mode changed.

CHANGELOG.md

100644100755
File mode changed.

LICENSE

100644100755
File mode changed.

README.md

100644100755
File mode changed.

android/.classpath

100644100755
File mode changed.

android/.gitignore

100644100755
File mode changed.

android/.project

100644100755
File mode changed.

android/.settings/org.eclipse.buildship.core.prefs

100644100755
File mode changed.

android/build.gradle

100644100755
File mode changed.

android/gradle.properties

100644100755
File mode changed.

android/gradle/wrapper/gradle-wrapper.properties

100644100755
File mode changed.

android/settings.gradle

100644100755
File mode changed.

android/src/main/AndroidManifest.xml

100644100755
File mode changed.

android/src/main/kotlin/com/example/user_location/UserLocationPlugin.kt

100644100755
File mode changed.

example.gif

100644100755
File mode changed.

example/.flutter-plugins-dependencies

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"location","dependencies":[]},{"name":"path_provider","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"user_location","dependencies":["location"]}]}

example/.gitignore

100644100755
File mode changed.

example/.metadata

100644100755
File mode changed.

example/README.md

100644100755
File mode changed.

example/android/.project

100644100755
File mode changed.

example/android/.settings/org.eclipse.buildship.core.prefs

100644100755
File mode changed.

example/android/app/.classpath

100644100755
File mode changed.

example/android/app/.project

100644100755
File mode changed.

example/android/app/.settings/org.eclipse.buildship.core.prefs

100644100755
File mode changed.

example/android/app/build.gradle

100644100755
File mode changed.

example/android/app/src/debug/AndroidManifest.xml

100644100755
File mode changed.

example/android/app/src/main/AndroidManifest.xml

100644100755
File mode changed.

example/android/app/src/main/kotlin/com/example/user_location_example/MainActivity.kt

100644100755
File mode changed.

example/android/app/src/main/res/drawable/launch_background.xml

100644100755
File mode changed.

example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png

100644100755
File mode changed.

example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png

100644100755
File mode changed.

example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png

100644100755
File mode changed.

example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png

100644100755
File mode changed.

example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png

100644100755
File mode changed.

example/android/app/src/main/res/values/styles.xml

100644100755
File mode changed.

example/android/app/src/profile/AndroidManifest.xml

100644100755
File mode changed.

example/android/build.gradle

100644100755
File mode changed.

example/android/gradle.properties

100644100755
File mode changed.

example/android/gradle/wrapper/gradle-wrapper.properties

100644100755
File mode changed.

example/android/settings.gradle

100644100755
File mode changed.

example/ios/Flutter/AppFrameworkInfo.plist

100644100755
File mode changed.

example/ios/Flutter/Debug.xcconfig

100644100755
File mode changed.

example/ios/Flutter/Release.xcconfig

100644100755
File mode changed.

example/ios/Runner.xcodeproj/project.pbxproj

100644100755
File mode changed.

example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.

example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

100644100755
File mode changed.

example/ios/Runner.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.

example/ios/Runner/AppDelegate.swift

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/Contents.json

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/AppIcon.appiconset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/LaunchImage.imageset/Contents.json

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/LaunchImage.imageset/LaunchImage.png

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/LaunchImage.imageset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/LaunchImage.imageset/[email protected]

100644100755
File mode changed.

example/ios/Runner/Assets.xcassets/LaunchImage.imageset/README.md

100644100755
File mode changed.

example/ios/Runner/Base.lproj/LaunchScreen.storyboard

100644100755
File mode changed.

example/ios/Runner/Base.lproj/Main.storyboard

100644100755
File mode changed.

example/ios/Runner/Info.plist

100644100755
File mode changed.

example/ios/Runner/Runner-Bridging-Header.h

100644100755
File mode changed.

example/lib/main.dart

100644100755
+34-31
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,41 @@ class HomePage extends StatelessWidget {
3333
});
3434

3535
return Scaffold(
36-
appBar: AppBar(title: Text("Plugin User Location")),
37-
body: FlutterMap(
38-
options: MapOptions(
39-
center: LatLng(27.7172, 85.3240),
40-
zoom: 15.0,
41-
plugins: [
42-
UserLocationPlugin(),
43-
],
44-
),
45-
layers: [
46-
TileLayerOptions(
47-
urlTemplate: "https://api.tiles.mapbox.com/v4/"
48-
"{id}/{z}/{x}/{y}@2x.png?access_token={accessToken}",
49-
additionalOptions: {
50-
'accessToken':
51-
'pk.eyJ1IjoiaWdhdXJhYiIsImEiOiJjazFhOWlkN2QwYzA5M2RyNWFvenYzOTV0In0.lzjuSBZC6LcOy_oRENLKCg',
52-
'id': 'mapbox.streets',
53-
},
54-
),
55-
MarkerLayerOptions(markers: markers),
56-
UserLocationOptions(
57-
context: context,
58-
mapController: mapController,
59-
markers: markers,
60-
onLocationUpdate: (LatLng pos) =>
61-
print("onLocationUpdate ${pos.toString()}"),
62-
updateMapLocationOnPositionChange: true,
63-
showMoveToCurrentLocationFloatingActionButton: true,
64-
verbose: false),
36+
appBar: AppBar(title: Text("Plugin User Location")),
37+
body: FlutterMap(
38+
options: MapOptions(
39+
center: LatLng(27.7172, 85.3240),
40+
zoom: 15.0,
41+
plugins: [
42+
UserLocationPlugin(),
6543
],
66-
mapController: mapController,
67-
));
44+
),
45+
layers: [
46+
TileLayerOptions(
47+
urlTemplate: "https://api.tiles.mapbox.com/v4/"
48+
"{id}/{z}/{x}/{y}@2x.png?access_token={accessToken}",
49+
additionalOptions: {
50+
'accessToken':
51+
'pk.eyJ1IjoiaWdhdXJhYiIsImEiOiJjazFhOWlkN2QwYzA5M2RyNWFvenYzOTV0In0.lzjuSBZC6LcOy_oRENLKCg',
52+
'id': 'mapbox.streets',
53+
},
54+
),
55+
MarkerLayerOptions(markers: markers),
56+
UserLocationOptions(
57+
context: context,
58+
mapController: mapController,
59+
markers: markers,
60+
onLocationUpdate: (LatLng pos) =>
61+
print("onLocationUpdate ${pos.toString()}"),
62+
updateMapLocationOnPositionChange: true,
63+
showMoveToCurrentLocationFloatingActionButton: true,
64+
fabBottom: 50,
65+
fabRight: 50,
66+
verbose: false),
67+
],
68+
mapController: mapController,
69+
),
70+
);
6871
}
6972

7073
void dispose() {

example/pubspec.yaml

100644100755
File mode changed.

example/test/widget_test.dart

100644100755
File mode changed.

ios/.gitignore

100644100755
File mode changed.

ios/Assets/.gitkeep

100644100755
File mode changed.

ios/Classes/SwiftUserLocationPlugin.swift

100644100755
File mode changed.

ios/Classes/UserLocationPlugin.h

100644100755
File mode changed.

ios/Classes/UserLocationPlugin.m

100644100755
File mode changed.

ios/user_location.podspec

100644100755
File mode changed.

lib/kotlin-reflect-sources.jar

100644100755
File mode changed.

lib/kotlin-reflect.jar

100644100755
File mode changed.

lib/kotlin-stdlib-jdk7-sources.jar

100644100755
File mode changed.

lib/kotlin-stdlib-jdk7.jar

100644100755
File mode changed.

lib/kotlin-stdlib-jdk8-sources.jar

100644100755
File mode changed.

lib/kotlin-stdlib-jdk8.jar

100644100755
File mode changed.

lib/kotlin-stdlib-sources.jar

100644100755
File mode changed.

lib/kotlin-stdlib.jar

100644100755
File mode changed.

lib/kotlin-test-sources.jar

100644100755
File mode changed.

lib/kotlin-test.jar

100644100755
File mode changed.

lib/src/user_location_layer.dart

100644100755
+50-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ class MapsPluginLayer extends StatefulWidget {
1818
_MapsPluginLayerState createState() => _MapsPluginLayerState();
1919
}
2020

21-
class _MapsPluginLayerState extends State<MapsPluginLayer> {
21+
class _MapsPluginLayerState extends State<MapsPluginLayer>
22+
with TickerProviderStateMixin {
2223
LatLng _currentLocation;
2324
Marker _locationMarker;
2425
EventChannel _stream = EventChannel('locationStatusStream');
@@ -128,10 +129,16 @@ class _MapsPluginLayerState extends State<MapsPluginLayer> {
128129
}
129130

130131
void _moveMapToCurrentLocation() {
131-
widget.options.mapController.move(
132+
animatedMapMove(
132133
LatLng(_currentLocation.latitude ?? LatLng(0, 0),
133134
_currentLocation.longitude ?? LatLng(0, 0)),
134-
widget.map.zoom ?? 15);
135+
widget.map.zoom ?? 15,
136+
widget.options.mapController,
137+
this);
138+
// widget.options.mapController.move(
139+
// LatLng(_currentLocation.latitude ?? LatLng(0, 0),
140+
// _currentLocation.longitude ?? LatLng(0, 0)),
141+
// widget.map.zoom ?? 15);
135142
}
136143

137144
void _handleLocationChanges() {
@@ -164,13 +171,14 @@ class _MapsPluginLayerState extends State<MapsPluginLayer> {
164171
Widget build(BuildContext context) {
165172
return widget.options.showMoveToCurrentLocationFloatingActionButton
166173
? Positioned(
167-
bottom: 20.0,
168-
right: 20.0,
169-
height: 40.0,
170-
width: 40.0,
174+
bottom: widget.options.fabBottom,
175+
right: widget.options.fabRight,
176+
height: widget.options.fabHeight,
177+
width: widget.options.fabWidth,
171178
child: InkWell(
172179
hoverColor: Colors.blueAccent[200],
173180
onTap: () {
181+
initialize();
174182
_moveMapToCurrentLocation();
175183
},
176184
child: widget.options
@@ -192,4 +200,39 @@ class _MapsPluginLayerState extends State<MapsPluginLayer> {
192200
)
193201
: Container();
194202
}
203+
204+
void animatedMapMove(
205+
LatLng destLocation, double destZoom, _mapController, vsync) {
206+
// Create some tweens. These serve to split up the transition from one location to another.
207+
// In our case, we want to split the transition be<tween> our current map center and the destination.
208+
final _latTween = Tween<double>(
209+
begin: _mapController.center.latitude, end: destLocation.latitude);
210+
final _lngTween = Tween<double>(
211+
begin: _mapController.center.longitude, end: destLocation.longitude);
212+
final _zoomTween = Tween<double>(begin: _mapController.zoom, end: destZoom);
213+
214+
// Create a animation controller that has a duration and a TickerProvider.
215+
var controller = AnimationController(
216+
duration: const Duration(milliseconds: 500), vsync: vsync);
217+
// The animation determines what path the animation will take. You can try different Curves values, although I found
218+
// fastOutSlowIn to be my favorite.
219+
Animation<double> animation =
220+
CurvedAnimation(parent: controller, curve: Curves.fastOutSlowIn);
221+
222+
controller.addListener(() {
223+
_mapController.move(
224+
LatLng(_latTween.evaluate(animation), _lngTween.evaluate(animation)),
225+
_zoomTween.evaluate(animation));
226+
});
227+
228+
animation.addStatusListener((status) {
229+
if (status == AnimationStatus.completed) {
230+
controller.dispose();
231+
} else if (status == AnimationStatus.dismissed) {
232+
controller.dispose();
233+
}
234+
});
235+
236+
controller.forward();
237+
}
195238
}

lib/src/user_location_options.dart

100644100755
+11-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_map/plugin_api.dart';
33
import 'package:latlong/latlong.dart';
4+
import 'package:location/location.dart';
45

56
class UserLocationOptions extends LayerOptions {
67
BuildContext context;
@@ -13,6 +14,11 @@ class UserLocationOptions extends LayerOptions {
1314
Widget moveToCurrentLocationFloatingActionButton;
1415
Function(LatLng) onLocationUpdate;
1516

17+
double fabBottom;
18+
double fabRight;
19+
double fabHeight;
20+
double fabWidth;
21+
1622
bool verbose;
1723

1824
UserLocationOptions(
@@ -24,5 +30,9 @@ class UserLocationOptions extends LayerOptions {
2430
this.updateMapLocationOnPositionChange: true,
2531
this.showMoveToCurrentLocationFloatingActionButton: true,
2632
this.moveToCurrentLocationFloatingActionButton,
27-
this.verbose: false});
33+
this.verbose: false,
34+
this.fabBottom: 20,
35+
this.fabHeight: 40,
36+
this.fabRight: 20,
37+
this.fabWidth: 40});
2838
}

lib/src/user_location_plugin.dart

100644100755
File mode changed.

lib/user_location.dart

100644100755
File mode changed.

lib/utils/LocationListener.dart

100644100755
File mode changed.

pubspec.yaml

100644100755
File mode changed.

test/user_location_test.dart

100644100755
File mode changed.

user_location.iml

100644100755
File mode changed.

0 commit comments

Comments
 (0)