Skip to content

Instantly share code, notes, and snippets.

@epsi95
Created April 11, 2020 03:55
Show Gist options
  • Save epsi95/f2398b5edc6ae0132891e3735d2d7f4d to your computer and use it in GitHub Desktop.
Save epsi95/f2398b5edc6ae0132891e3735d2d7f4d to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong/latlong.dart';
import 'package:location/location.dart';
class ReportCorona extends StatefulWidget {
@override
_ReportCoronaState createState() => _ReportCoronaState();
}
class _ReportCoronaState extends State<ReportCorona>
with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController controller;
Location location = Location();
bool _serviceEnabled;
PermissionStatus _permissionGranted;
LocationData _locationData;
MapController _mapController = MapController();
AnimationStatus _animationStatus;
List<Marker> _markers = [
Marker(
width: 80.0,
height: 80.0,
point: LatLng(51.5, -0.09),
builder: (ctx) => Container(
child: FlutterLogo(),
),
)
];
@override
void initState() {
controller =
AnimationController(vsync: this, duration: Duration(seconds: 2));
animation = CurvedAnimation(parent: controller, curve: Curves.easeInOut);
controller.addStatusListener((status) {
_animationStatus = status;
// if (status == AnimationStatus.completed) {
// controller.reverse();
// } else if (status == AnimationStatus.dismissed) {
// controller.forward();
// }
});
controller.addListener(() {
setState(() {});
});
// controller.forward();
super.initState();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
void initiateLocation() async {
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return;
}
}
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
return;
}
}
_locationData = await location.getLocation();
location.onLocationChanged.listen((LocationData currentLocation) {
// Use current location
updateLocation(currentLocation);
});
}
void updateLocation(LocationData locationData) {}
@override
Widget build(BuildContext context) {
return Scaffold(
floatingActionButton: FloatingActionButton(
child: Text(animation.value.toString()),
onPressed: () {
_mapController.onReady.then((result) {
LatLng TL = _mapController.bounds.northWest;
LatLng TR = _mapController.bounds.northEast;
// LatLng BL = _mapController.bounds.southWest;
LatLng BR = _mapController.bounds.southWest;
LatLng currentCenter = LatLng((TL.latitude + BR.latitude) / 2,
(TL.longitude + TR.longitude) / 2);
double currentZoomLevel = _mapController.zoom;
print("zoomLevel " + currentZoomLevel.toString());
print(_animationStatus);
// print(currentCenter);
// Animation<double> latAnimation =
// Tween(begin: currentCenter.latitude, end: 51.5)
// .animate(animation);
// Animation<double> lonAnimation =
// Tween(begin: currentCenter.longitude, end: -0.09)
// .animate(animation);
Tween<double> zoomAnimation =
Tween(begin: currentZoomLevel, end: 13);
if (_animationStatus == AnimationStatus.completed) {
controller.reverse();
if (currentZoomLevel != 13) {
controller.addListener(() {
// currentZoomLevel = zoomAnimation.evaluate(animation);
// print(currentZoomLevel);
print(controller.value.toString() +
" " +
animation.value.toString());
});
}
} else if (_animationStatus == AnimationStatus.dismissed) {
controller.forward();
if (currentZoomLevel != 13) {
controller.addListener(() {
// currentZoomLevel = zoomAnimation.evaluate(animation);
// print(currentZoomLevel);
print(controller.value.toString() +
" " +
animation.value.toString());
});
}
} else if (_animationStatus == null) {
controller.forward();
if (currentZoomLevel != 13) {
controller.addListener(() {
// currentZoomLevel = zoomAnimation.evaluate(animation);
// print(currentZoomLevel);
print(controller.value.toString() +
" " +
animation.value.toString());
});
}
}
// if(currentZoomLevel > )
// print("FAB tapped");
// print(zoomAnimation.evaluate(animation));
// print(controller.value);
// _mapController.move(LatLng(51.5, -0.09), 13.0);
});
},
),
body: FlutterMap(
mapController: _mapController,
options: MapOptions(
onTap: (LatLng tappedLocation) {
print(tappedLocation);
_markers.add(
Marker(
width: 80.0,
height: 80.0,
point: tappedLocation,
builder: (ctx) => Container(
child: FlutterLogo(),
),
),
);
setState(() {});
},
center: LatLng(51.5, -0.09),
zoom: 13.0,
),
layers: [
TileLayerOptions(
urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
subdomains: ['a', 'b', 'c'],
),
MarkerLayerOptions(
markers: _markers,
),
CircleLayerOptions(
circles: [
CircleMarker(
point: LatLng(51.5, -0.09),
radius: 1000.0,
useRadiusInMeter: true,
color: Colors.red.withOpacity(0.5),
borderColor: Colors.red,
borderStrokeWidth: 5.0),
],
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment