Skip to content

Commit

Permalink
fix: Improve map for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Myzel394 committed Sep 26, 2023
1 parent 006d635 commit 6587c0d
Show file tree
Hide file tree
Showing 9 changed files with 203 additions and 135 deletions.
6 changes: 3 additions & 3 deletions lib/screens/LocationsOverviewScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -834,14 +834,14 @@ class _LocationsOverviewScreenState extends State<LocationsOverviewScreen>
final lastCenter = settings.getLastMapLocation()?.toLatLng();
final colorOpacityMultiplier = selectedViewID == null ? 1.0 : .1;
return LocusFlutterMap(
mapController: flutterMapController,
options: MapOptions(
flutterMapController: flutterMapController,
flutterMapOptions: MapOptions(
maxZoom: 18,
minZoom: 2,
center: lastCenter ?? getFallbackLocation(context),
zoom: lastCenter == null ? FALLBACK_LOCATION_ZOOM_LEVEL : 13,
),
children: [
flutterChildren: [
CircleLayer(
circles: circleLocations
.map((data) {
Expand Down
66 changes: 31 additions & 35 deletions lib/screens/locations_overview_screen_widgets/ViewDetails.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@ import 'dart:async';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get_time_ago/get_time_ago.dart';
import 'package:latlong2/latlong.dart';
import 'package:locus/services/view_service/index.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:locus/utils/date.dart';
import 'package:locus/utils/navigation.dart';
import 'package:latlong2/latlong.dart';

import 'package:locus/utils/location/index.dart';
import 'package:locus/utils/permissions/has-granted.dart';
import 'package:locus/utils/permissions/request.dart';
import 'package:locus/widgets/OpenInMaps.dart';
import 'package:map_launcher/map_launcher.dart';

import '../../constants/spacing.dart';
import '../../services/location_point_service.dart';
import '../../utils/icon.dart';
import '../../utils/theme.dart';
import '../../widgets/BentoGridElement.dart';
import '../../widgets/LocusFlutterMap.dart';
import '../../widgets/RequestLocationPermissionMixin.dart';
import '../ViewDetailsScreen.dart';

class ViewDetails extends StatefulWidget {
final TaskView? view;
Expand Down Expand Up @@ -54,36 +50,37 @@ class _ViewDetailsState extends State<ViewDetails> {
oldLastLocation = oldWidget.location;
}

Widget buildHeadingMap(final LocationPointService lastLocation,) {
Widget buildHeadingMap(
final LocationPointService lastLocation,
) {
return ClipRRect(
borderRadius: BorderRadius.circular(LARGE_SPACE),
child: SizedBox(
height: 200,
child: LocusFlutterMap(
options: MapOptions(
flutterMapOptions: MapOptions(
center: LatLng(
lastLocation.latitude,
lastLocation.longitude,
),
zoom: 13,
),
children: [
flutterChildren: [
MarkerLayer(
markers: [
Marker(
point: LatLng(
lastLocation.latitude,
lastLocation.longitude,
),
builder: (context) =>
Transform.rotate(
angle: lastLocation.heading!,
child: Icon(
CupertinoIcons.location_north_fill,
color: getPrimaryColorShades(context)[0],
size: 30,
),
),
builder: (context) => Transform.rotate(
angle: lastLocation.heading!,
child: Icon(
CupertinoIcons.location_north_fill,
color: getPrimaryColorShades(context)[0],
size: 30,
),
),
),
],
)
Expand Down Expand Up @@ -122,8 +119,8 @@ class _ViewDetailsState extends State<ViewDetails> {
title: lastLocation.altitude == null
? l10n.unknownValue
: l10n.locations_values_altitude_m(
lastLocation.altitude!.round(),
),
lastLocation.altitude!.round(),
),
icon: platformThemeData(
context,
material: (_) => Icons.height_rounded,
Expand All @@ -136,8 +133,8 @@ class _ViewDetailsState extends State<ViewDetails> {
title: lastLocation.speed == null
? l10n.unknownValue
: l10n.locations_values_speed_kmh(
(lastLocation.speed! * 3.6).round(),
),
(lastLocation.speed! * 3.6).round(),
),
icon: platformThemeData(
context,
material: (_) => Icons.speed,
Expand All @@ -150,8 +147,8 @@ class _ViewDetailsState extends State<ViewDetails> {
title: lastLocation.batteryLevel == null
? l10n.unknownValue
: l10n.locations_values_battery_value(
(lastLocation.batteryLevel! * 100).round(),
),
(lastLocation.batteryLevel! * 100).round(),
),
icon: getIconDataForBatteryLevel(
context,
lastLocation.batteryLevel,
Expand All @@ -163,8 +160,8 @@ class _ViewDetailsState extends State<ViewDetails> {
title: lastLocation.batteryState == null
? l10n.unknownValue
: l10n.locations_values_batteryState_value(
lastLocation.batteryState!.name,
),
lastLocation.batteryState!.name,
),
icon: Icons.cable_rounded,
type: BentoType.tertiary,
description: l10n.locations_values_batteryState_description,
Expand Down Expand Up @@ -242,10 +239,9 @@ class _DistanceBentoElementState extends State<DistanceBentoElement>
showPlatformModalSheet(
context: context,
material: MaterialModalSheetData(),
builder: (context) =>
OpenInMaps(
destination: widget.lastLocation.asCoords(),
),
builder: (context) => OpenInMaps(
destination: widget.lastLocation.asCoords(),
),
);
},
title: (() {
Expand Down Expand Up @@ -342,10 +338,10 @@ class _LastLocationBentoElementState extends State<LastLocationBentoElement> {
title: showAbsolute
? formatDateTimeHumanReadable(widget.lastLocation.createdAt)
: GetTimeAgo.parse(
DateTime.now().subtract(
DateTime.now().difference(widget.lastLocation.createdAt),
),
),
DateTime.now().subtract(
DateTime.now().difference(widget.lastLocation.createdAt),
),
),
icon: Icons.location_on_rounded,
description: l10n.locations_values_lastLocation_description,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class GeoLocationAlarmPreview extends StatelessWidget {
Widget build(BuildContext context) {
final locationFetchers = context.watch<LocationFetchers>();
final lastLocation =
locationFetchers
.getLocations(view)
.lastOrNull
?.asLatLng();
locationFetchers.getLocations(view).lastOrNull?.asLatLng();

return Column(
mainAxisSize: MainAxisSize.min,
Expand All @@ -49,13 +46,13 @@ class GeoLocationAlarmPreview extends StatelessWidget {
child: IgnorePointer(
ignoring: true,
child: LocusFlutterMap(
options: MapOptions(
flutterMapOptions: MapOptions(
center: alarm.center,
maxZoom: 18,
// create zoom based of radius
zoom: getZoomLevelForRadius(alarm.radius),
),
children: [
flutterChildren: [
CircleLayer(
circles: [
CircleMarker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
import 'package:latlong2/latlong.dart';
import 'package:locus/constants/spacing.dart';
import 'package:locus/constants/values.dart';
import 'package:locus/utils/location/get-fallback-location.dart';
import 'package:locus/widgets/LocationsMap.dart';
import 'package:locus/widgets/LocusFlutterMap.dart';
import 'package:locus/widgets/MapBanner.dart';
import 'package:shimmer/shimmer.dart';
Expand All @@ -19,6 +18,8 @@ const INITIAL_RADIUS = 50.0;
class LocationRadiusSelectorMap extends StatefulWidget {
final MapController? flutterMapController;
final apple_maps.AppleMapController? appleMapController;
final void Function(apple_maps.AppleMapController controller)?
onAppleMapCreated;
final LatLng? center;
final double? radius;
final void Function(LatLng)? onLocationChange;
Expand All @@ -32,9 +33,10 @@ class LocationRadiusSelectorMap extends StatefulWidget {
this.appleMapController,
this.onLocationChange,
this.onRadiusChange,
this.enableRealTimeRadiusUpdate = false,
this.onAppleMapCreated,
this.center,
this.radius,
this.enableRealTimeRadiusUpdate = false,
this.children = const [],
});

Expand Down Expand Up @@ -137,37 +139,35 @@ class _LocationRadiusSelectorMapState extends State<LocationRadiusSelectorMap> {
child: IgnorePointer(
ignoring: isInScaleMode,
child: LocusFlutterMap(
mapController: widget.flutterMapController!,
options: MapOptions(
onLongPress: (_, __) {
Vibration.vibrate(duration: 100);
flutterMapController: widget.flutterMapController,
appleMapController: widget.appleMapController,
initialZoom: 13.0,
onAppleMapCreated: widget.onAppleMapCreated,
onTap: (location) {
location = LatLng(
location.latitude,
location.longitude,
);

widget.onLocationChange?.call(location);

if (radius == null) {
setState(() {
isInScaleMode = true;
radius = INITIAL_RADIUS;
center = location;
});
},
center: getFallbackLocation(context),
zoom: FALLBACK_LOCATION_ZOOM_LEVEL,
onTap: (tapPosition, location) {
location = LatLng(
location.latitude,
location.longitude,
);

widget.onLocationChange?.call(location);

if (radius == null) {
setState(() {
radius = INITIAL_RADIUS;
center = location;
});

widget.onRadiusChange?.call(INITIAL_RADIUS);
}
},
maxZoom: 18,
),
children: [

widget.onRadiusChange?.call(INITIAL_RADIUS);
}
},
onLongPress: (location) {
Vibration.vibrate(duration: 100);

setState(() {
isInScaleMode = true;
});
},
flutterChildren: [
if (isInScaleMode)
Shimmer.fromColors(
baseColor: Colors.red,
Expand All @@ -180,6 +180,27 @@ class _LocationRadiusSelectorMapState extends State<LocationRadiusSelectorMap> {
followOnLocationUpdate: FollowOnLocationUpdate.once,
)
],
appleMapCircles: {
if (center != null && radius != null)
if (isInScaleMode)
apple_maps.Circle(
circleId: apple_maps.CircleId('radius-$radius-scale'),
center: toAppleMapsCoordinates(center!),
radius: radius!,
fillColor: Colors.orangeAccent.withOpacity(.35),
strokeColor: Colors.orangeAccent,
strokeWidth: 2,
)
else
apple_maps.Circle(
circleId: apple_maps.CircleId('radius-$radius'),
center: toAppleMapsCoordinates(center!),
radius: radius!,
fillColor: Colors.red.withOpacity(.25),
strokeColor: Colors.red,
strokeWidth: 2,
)
},
),
),
),
Expand Down
26 changes: 11 additions & 15 deletions lib/screens/view_alarm_screen_widgets/ProximityAlarmPreview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:flutter_map_location_marker/flutter_map_location_marker.dart';
import 'package:flutter_osm_plugin/flutter_osm_plugin.dart';
import 'package:flutter_platform_widgets/flutter_platform_widgets.dart';
import 'package:latlong2/latlong.dart';
import 'package:locus/constants/spacing.dart';
Expand Down Expand Up @@ -35,15 +34,12 @@ class ProximityAlarmPreview extends StatelessWidget {
final centerPosition = currentLocation.currentPosition == null
? getFallbackLocation(context)
: LatLng(
currentLocation.currentPosition!.latitude,
currentLocation.currentPosition!.longitude,
);
currentLocation.currentPosition!.latitude,
currentLocation.currentPosition!.longitude,
);
final locationFetchers = context.watch<LocationFetchers>();
final lastLocation =
locationFetchers
.getLocations(view)
.lastOrNull
?.asLatLng();
locationFetchers.getLocations(view).lastOrNull?.asLatLng();

return Column(
mainAxisSize: MainAxisSize.min,
Expand All @@ -52,12 +48,12 @@ class ProximityAlarmPreview extends StatelessWidget {
title: Text(
alarm.radius > 10000
? l10n.location_addAlarm_radiusBased_radius_kilometers(
double.parse(
(alarm.radius / 1000).toStringAsFixed(1),
),
)
double.parse(
(alarm.radius / 1000).toStringAsFixed(1),
),
)
: l10n.location_addAlarm_radiusBased_radius_meters(
alarm.radius.round()),
alarm.radius.round()),
),
leading: getIconForLocationRadiusBasedTrigger(context, alarm.type),
trailing: PlatformIconButton(
Expand All @@ -73,13 +69,13 @@ class ProximityAlarmPreview extends StatelessWidget {
child: IgnorePointer(
ignoring: true,
child: LocusFlutterMap(
options: MapOptions(
flutterMapOptions: MapOptions(
center: centerPosition,
maxZoom: 18,
// create zoom based of radius
zoom: getZoomLevelForRadius(alarm.radius),
),
children: [
flutterChildren: [
CurrentLocationLayer(
positionStream: currentLocation.locationMarkerStream,
followOnLocationUpdate: FollowOnLocationUpdate.never,
Expand Down
Loading

0 comments on commit 6587c0d

Please sign in to comment.