Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

243-fix-crash-when-no-location-permission #244

Merged
merged 5 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:location/location.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:maplibre_gl_example/get_map_informations.dart';
import 'package:maplibre_gl_example/given_bounds.dart';
import 'package:maplibre_gl_example/no_location_permission_page.dart';

import 'animate_camera.dart';
import 'annotation_order_maps.dart';
Expand Down Expand Up @@ -54,6 +55,7 @@ final List<ExamplePage> _allPages = <ExamplePage>[
const Sources(),
const GivenBoundsPage(),
const GetMapInfoPage(),
const NoLocationPermissionPage(),
];

class MapsDemo extends StatefulWidget {
Expand All @@ -64,11 +66,6 @@ class MapsDemo extends StatefulWidget {
}

class _MapsDemoState extends State<MapsDemo> {
@override
void initState() {
super.initState();
}

/// Determine the android version of the phone and turn off HybridComposition
/// on older sdk versions to improve performance for these
///
Expand All @@ -86,7 +83,7 @@ class _MapsDemoState extends State<MapsDemo> {
}

void _pushPage(BuildContext context, ExamplePage page) async {
if (!kIsWeb) {
if (!kIsWeb && page.needsLocationPermission) {
final location = Location();
final hasPermissions = await location.hasPermission();
if (hasPermissions != PermissionStatus.granted) {
Expand Down
5 changes: 0 additions & 5 deletions example/lib/map_ui.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ class MapUiBodyState extends State<MapUiBody> {
List<Object>? _featureQueryFilter;
Fill? _selectedFill;

@override
void initState() {
super.initState();
}

void _onMapChanged() {
setState(() {
_extractMapInfo();
Expand Down
61 changes: 61 additions & 0 deletions example/lib/no_location_permission_page.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import 'package:flutter/material.dart';
import 'package:maplibre_gl/mapbox_gl.dart';

import 'page.dart';

class NoLocationPermissionPage extends ExamplePage {
const NoLocationPermissionPage({super.key})
: super(
const Icon(Icons.gps_off),
'Using a map without user location/permission',
needsLocationPermission: false,
);

@override
Widget build(BuildContext context) {
return const NoLocationPermissionBody();
}
}

class NoLocationPermissionBody extends StatefulWidget {
const NoLocationPermissionBody({super.key});

@override
State<NoLocationPermissionBody> createState() =>
_NoLocationPermissionBodyState();
}

class _NoLocationPermissionBodyState extends State<NoLocationPermissionBody> {
@override
Widget build(BuildContext context) {
return MaplibreMap(
initialCameraPosition: const CameraPosition(
target: LatLng(-33.852, 151.211),
zoom: 11.0,
),
styleString: '''{
"version": 8,
"sources": {
"OSM": {
"type": "raster",
"tiles": [
"https://a.tile.openstreetmap.org/{z}/{x}/{y}.png",
"https://b.tile.openstreetmap.org/{z}/{x}/{y}.png",
"https://c.tile.openstreetmap.org/{z}/{x}/{y}.png"
],
"tileSize": 256,
"attribution": "© OpenStreetMap contributors",
"maxzoom": 18
}
},
"layers": [
{
"id": "OSM-layer",
"source": "OSM",
"type": "raster"
}
]
}''',
);
}
}
8 changes: 7 additions & 1 deletion example/lib/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
import 'package:flutter/material.dart';

abstract class ExamplePage extends StatelessWidget {
const ExamplePage(this.leading, this.title, {super.key});
const ExamplePage(
this.leading,
this.title, {
this.needsLocationPermission = true,
super.key,
});

final Widget leading;
final String title;
final bool needsLocationPermission;
}
4 changes: 2 additions & 2 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ packages:
dependency: transitive
description:
name: image
sha256: "8e9d133755c3e84c73288363e6343157c383a0c6c56fc51afcc5d4d7180306d6"
sha256: a72242c9a0ffb65d03de1b7113bc4e189686fc07c7147b8b41811d0dd0e0d9bf
url: "https://pub.dev"
source: hosted
version: "3.3.0"
version: "4.0.17"
js:
dependency: transitive
description:
Expand Down
10 changes: 8 additions & 2 deletions lib/src/mapbox_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class MaplibreMap extends StatefulWidget {
this.trackCameraPosition = false,
this.myLocationEnabled = false,
this.myLocationTrackingMode = MyLocationTrackingMode.None,
this.myLocationRenderMode = MyLocationRenderMode.COMPASS,
this.myLocationRenderMode = MyLocationRenderMode.NORMAL,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good approach, but we should note this in the release notes, since it's a breaking change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR for changelog docs: #247

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing the changelog for me :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I adjust the documentation to highlight that you only need location permission if you use specific properties?

this.logoViewMargins,
this.compassViewPosition,
this.compassViewMargins,
Expand All @@ -55,7 +55,13 @@ class MaplibreMap extends StatefulWidget {
],
this.useDelayedDisposal,
this.useHybridCompositionOverride,
}) : assert(annotationOrder.length <= 4),
}) : assert(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

myLocationRenderMode != MyLocationRenderMode.NORMAL
? myLocationEnabled
: true,
"$myLocationRenderMode requires [myLocationEnabled] set to true.",
),
assert(annotationOrder.length <= 4),
assert(annotationConsumeTapEvents.length > 0),
super(key: key);

Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ packages:
dependency: transitive
description:
name: image
sha256: "8e9d133755c3e84c73288363e6343157c383a0c6c56fc51afcc5d4d7180306d6"
sha256: a72242c9a0ffb65d03de1b7113bc4e189686fc07c7147b8b41811d0dd0e0d9bf
url: "https://pub.dev"
source: hosted
version: "3.3.0"
version: "4.0.17"
js:
dependency: transitive
description:
Expand Down Expand Up @@ -161,4 +161,4 @@ packages:
version: "6.2.2"
sdks:
dart: ">=3.0.0-0 <4.0.0"
flutter: ">=2.0.0"
flutter: ">=2.8.1"