Skip to content

Commit

Permalink
Only check permissions if location is used
Browse files Browse the repository at this point in the history
The apple_maps_plugin will only request the users permission for location,
if the userLocation is actually used. Fixes #6
  • Loading branch information
LuisThein committed Mar 3, 2020
1 parent f4a5180 commit d4eee9f
Show file tree
Hide file tree
Showing 21 changed files with 477 additions and 215 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
.dart_tool/
pubspec.lock
flutter_export_environment.sh

resources/
examples/all_plugins/pubspec.yaml

Podfile
Expand All @@ -29,6 +29,8 @@ keystore.properties
gradlew
gradlew.bat
gradle-wrapper.jar
.flutter-plugins-dependencies
flutter_export_environment.sh
*.iml

GeneratedPluginRegistrant.h
Expand All @@ -39,4 +41,4 @@ build/

.project
.classpath
.settings
.settings
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ This plugin was based on the [google_maps_flutter]("https://pub.dev/packages/goo

# Screenshots

| Example 1 | Example 2 |
| :---------------------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------------------: |
| ![Example 1](https://github.com/LuisThein/apple_maps_flutter/blob/master/resources/example_img01.png) | ![Example 2](https://github.com/LuisThein/apple_maps_flutter/blob/master/resources/example_img02.png) |
| Example 1 | Example 2 |
| :-------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------: |
| ![Example 1](https://luisthein.de/apple-maps-plugin-images/example_img01-min.png) | ![Example 2](https://luisthein.de/apple-maps-plugin-images/example_img02-min.png) |

# iOS

Expand Down
1 change: 1 addition & 0 deletions example/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
org.gradle.jvmargs=-Xmx1536M

android.enableR8=true
18 changes: 18 additions & 0 deletions example/ios/Flutter/Flutter.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# NOTE: This podspec is NOT to be published. It is only used as a local source!
#

Pod::Spec.new do |s|
s.name = 'Flutter'
s.version = '1.0.0'
s.summary = 'High-performance, high-fidelity mobile apps.'
s.description = <<-DESC
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
DESC
s.homepage = 'https://flutter.io'
s.license = { :type => 'MIT' }
s.author = { 'Flutter Dev Team' => '[email protected]' }
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.vendored_frameworks = 'Flutter.framework'
end
2 changes: 2 additions & 0 deletions example/ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export "FLUTTER_TARGET=/Users/luis/workspace/flutter_packages/apple_maps_flutter
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "FLUTTER_FRAMEWORK_DIR=/Users/luis/development/flutter/bin/cache/artifacts/engine/ios"
export "FLUTTER_BUILD_NAME=1.0.0"
export "FLUTTER_BUILD_NUMBER=1"
export "TRACK_WIDGET_CREATION=true"
84 changes: 50 additions & 34 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,51 +15,67 @@ def parse_KV_file(file, separator='=')
if !File.exists? file_abs_path
return [];
end
pods_ary = []
generated_key_values = {}
skip_line_start_symbols = ["#", "/"]
File.foreach(file_abs_path) { |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
pods_ary.push({:name => podname, :path => podpath});
else
puts "Invalid plugin specification: #{line}"
end
}
return pods_ary
File.foreach(file_abs_path) do |line|
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
plugin = line.split(pattern=separator)
if plugin.length == 2
podname = plugin[0].strip()
path = plugin[1].strip()
podpath = File.expand_path("#{path}", file_abs_path)
generated_key_values[podname] = podpath
else
puts "Invalid plugin specification: #{line}"
end
end
generated_key_values
end

target 'Runner' do
use_frameworks!
use_modular_headers!

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
# Flutter Pod

# Flutter Pods
generated_xcode_build_settings = parse_KV_file('./Flutter/Generated.xcconfig')
if generated_xcode_build_settings.empty?
puts "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first."
end
generated_xcode_build_settings.map { |p|
if p[:name] == 'FLUTTER_FRAMEWORK_DIR'
symlink = File.join('.symlinks', 'flutter')
File.symlink(File.dirname(p[:path]), symlink)
pod 'Flutter', :path => File.join(symlink, File.basename(p[:path]))
copied_flutter_dir = File.join(__dir__, 'Flutter')
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.

generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
unless File.exist?(generated_xcode_build_settings_path)
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
}
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];

unless File.exist?(copied_framework_path)
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
end
unless File.exist?(copied_podspec_path)
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
end
end

# Keep pod path relative so it can be checked into Podfile.lock.
pod 'Flutter', :path => 'Flutter'

# Plugin Pods

# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
# referring to absolute paths on developers' machines.
system('rm -rf .symlinks')
system('mkdir -p .symlinks/plugins')
plugin_pods = parse_KV_file('../.flutter-plugins')
plugin_pods.map { |p|
symlink = File.join('.symlinks', 'plugins', p[:name])
File.symlink(p[:path], symlink)
pod p[:name], :path => File.join(symlink, 'ios')
}
plugin_pods.each do |name, path|
symlink = File.join('.symlinks', 'plugins', name)
File.symlink(path, symlink)
pod name, :path => File.join(symlink, 'ios')
end
end

# Prevent Cocoapods from embedding a second Flutter framework and causing an error with the new Xcode build system.
Expand Down
6 changes: 3 additions & 3 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ PODS:

DEPENDENCIES:
- apple_maps_flutter (from `.symlinks/plugins/apple_maps_flutter/ios`)
- Flutter (from `.symlinks/flutter/ios`)
- Flutter (from `Flutter`)

EXTERNAL SOURCES:
apple_maps_flutter:
:path: ".symlinks/plugins/apple_maps_flutter/ios"
Flutter:
:path: ".symlinks/flutter/ios"
:path: Flutter

SPEC CHECKSUMS:
apple_maps_flutter: 45925bdf704b86f713fcf6979ee1999d17b2a6e0
Flutter: 0e3d915762c693b495b44d77113d4970485de6ec

PODFILE CHECKSUM: b6a0a141693093b304368d08511b46cf3d1d0ac5
PODFILE CHECKSUM: 083258d7f5e80b42ea9bfee905fe93049bc04c64

COCOAPODS: 1.8.3
2 changes: 2 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:apple_maps_flutter_example/padding.dart';
import 'package:apple_maps_flutter_example/place_annotation.dart';
import 'package:apple_maps_flutter_example/place_polyline.dart';
import 'package:apple_maps_flutter_example/scrolling_map.dart';
import 'package:flutter/material.dart';
import 'animate_camera.dart';
import 'map_click.dart';
Expand All @@ -24,6 +25,7 @@ final List<Page> _allPages = <Page>[
PlaceAnnotationPage(),
AnnotationIconsPage(),
PlacePolylinePage(),
ScrollingMapPage(),
];

class MapsDemo extends StatelessWidget {
Expand Down
115 changes: 115 additions & 0 deletions example/lib/scrolling_map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore_for_file: public_member_api_docs

import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:apple_maps_flutter/apple_maps_flutter.dart';

import 'page.dart';

class ScrollingMapPage extends Page {
ScrollingMapPage() : super(const Icon(Icons.map), 'Scrolling map');

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

class ScrollingMapBody extends StatelessWidget {
const ScrollingMapBody();

final LatLng center = const LatLng(32.080664, 34.9563837);

@override
Widget build(BuildContext context) {
return ListView(
children: <Widget>[
Card(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: Column(
children: <Widget>[
const Padding(
padding: EdgeInsets.only(bottom: 12.0),
child: Text('This map consumes all touch events.'),
),
Center(
child: SizedBox(
width: 300.0,
height: 300.0,
child: AppleMap(
initialCameraPosition: CameraPosition(
target: center,
zoom: 11.0,
),
gestureRecognizers:
<Factory<OneSequenceGestureRecognizer>>[
Factory<OneSequenceGestureRecognizer>(
() => EagerGestureRecognizer(),
),
].toSet(),
),
),
),
],
),
),
),
Card(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 30.0),
child: Column(
children: <Widget>[
const Text('This map doesn\'t consume the vertical drags.'),
const Padding(
padding: EdgeInsets.only(bottom: 12.0),
child:
Text('It still gets other gestures (e.g scale or tap).'),
),
Center(
child: SizedBox(
width: 300.0,
height: 300.0,
child: AppleMap(
initialCameraPosition: CameraPosition(
target: center,
zoom: 11.0,
),
annotations: Set<Annotation>.of(
<Annotation>[
Annotation(
annotationId: AnnotationId("test_Annotation_id"),
position: LatLng(
center.latitude,
center.longitude,
),
infoWindow: const InfoWindow(
title: 'An interesting location',
snippet: '*',
),
)
],
),
gestureRecognizers:
<Factory<OneSequenceGestureRecognizer>>[
Factory<OneSequenceGestureRecognizer>(
() => ScaleGestureRecognizer(),
),
].toSet(),
),
),
),
],
),
),
),
],
);
}
}
Loading

0 comments on commit d4eee9f

Please sign in to comment.