From d2db88c1e19924b66a9a581baa265e1444b0f420 Mon Sep 17 00:00:00 2001 From: Rene Floor Date: Mon, 6 May 2024 09:30:09 +0200 Subject: [PATCH] chore: apply flutter_lints and update Android example (#64) * chore: Add flutter_lints and apply all suggestions Signed-off-by: Rene Floor * chore: Update Flutter version Signed-off-by: Rene Floor * chore: Update android and gradle Signed-off-by: Rene Floor --------- Signed-off-by: Rene Floor --- .github/workflows/publish.yml | 2 +- analysis_options.yaml | 2 + example/analysis_options.yaml | 2 + example/android/app/build.gradle | 7 +- .../android/app/src/debug/AndroidManifest.xml | 3 +- .../android/app/src/main/AndroidManifest.xml | 4 +- .../app/src/profile/AndroidManifest.xml | 3 +- example/android/build.gradle | 10 +- .../gradle/wrapper/gradle-wrapper.properties | 2 +- example/ios/Flutter/AppFrameworkInfo.plist | 2 +- example/ios/Podfile | 2 +- example/ios/Podfile.lock | 28 ++-- example/ios/Runner.xcodeproj/project.pbxproj | 13 +- .../xcshareddata/xcschemes/Runner.xcscheme | 2 +- example/ios/Runner/Info.plist | 4 + example/lib/main.dart | 50 +++---- example/pubspec.yaml | 58 +------- lib/platform_maps_flutter.dart | 6 +- lib/src/bitmap.dart | 14 +- lib/src/camera.dart | 68 +++++----- lib/src/cap.dart | 22 +-- lib/src/circle.dart | 60 ++++----- lib/src/controller.dart | 60 ++++----- lib/src/joint_type.dart | 22 +-- lib/src/location.dart | 59 ++++----- lib/src/marker.dart | 125 ++++++++---------- lib/src/pattern_item.dart | 36 +++-- lib/src/platform_maps.dart | 61 ++++----- lib/src/polygon.dart | 56 ++++---- lib/src/polyline.dart | 33 +++-- lib/src/ui.dart | 10 +- pubspec.yaml | 4 +- 32 files changed, 372 insertions(+), 458 deletions(-) create mode 100644 analysis_options.yaml create mode 100644 example/analysis_options.yaml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index f84bd83..66cfe30 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -17,7 +17,7 @@ jobs: - name: Install Flutter uses: subosito/flutter-action@v1 with: - flutter-version: '2.0.3' + flutter-version: '3.19.1' - name: Install dependencies run: flutter pub get - name: Run dart analyze diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..448d91f --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,2 @@ +include: package:flutter_lints/flutter.yaml + diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 0000000..448d91f --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,2 @@ +include: package:flutter_lints/flutter.yaml + diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index b8b72b9..66005b7 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { - compileSdkVersion 30 + compileSdkVersion 34 sourceSets { main.java.srcDirs += 'src/main/kotlin' @@ -35,8 +35,8 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.flutter_platform_maps_example" - minSdkVersion 16 - targetSdkVersion 30 + minSdkVersion 20 + targetSdkVersion 34 versionCode flutterVersionCode.toInteger() versionName flutterVersionName } @@ -48,6 +48,7 @@ android { signingConfig signingConfigs.debug } } + namespace 'com.example.flutter_platform_maps_example' } flutter { diff --git a/example/android/app/src/debug/AndroidManifest.xml b/example/android/app/src/debug/AndroidManifest.xml index 80f3abe..f880684 100644 --- a/example/android/app/src/debug/AndroidManifest.xml +++ b/example/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,4 @@ - + diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index dc71632..76fd42f 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,4 @@ - + @@ -9,6 +8,7 @@ + diff --git a/example/android/build.gradle b/example/android/build.gradle index c505a86..d02fac2 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,12 +1,12 @@ buildscript { - ext.kotlin_version = '1.3.50' + ext.kotlin_version = '1.8.21' repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.0' + classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } @@ -14,7 +14,7 @@ buildscript { allprojects { repositories { google() - jcenter() + mavenCentral() } } @@ -26,6 +26,6 @@ subprojects { project.evaluationDependsOn(':app') } -task clean(type: Delete) { +tasks.register("clean", Delete) { delete rootProject.buildDir } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index bc6a58a..cfe88f6 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d48..7c56964 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 12.0 diff --git a/example/ios/Podfile b/example/ios/Podfile index 252d9ec..2c068c4 100644 --- a/example/ios/Podfile +++ b/example/ios/Podfile @@ -1,5 +1,5 @@ # Uncomment this line to define a global platform for your project -platform :ios, '9.0' +platform :ios, '12.0' # CocoaPods analytics sends network stats synchronously affecting flutter build latency. ENV['COCOAPODS_DISABLE_STATS'] = 'true' diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 2f9269b..2576716 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -2,19 +2,19 @@ PODS: - apple_maps_flutter (0.0.1): - Flutter - Flutter (1.0.0) - - google_maps_flutter (0.0.1): + - google_maps_flutter_ios (0.0.1): - Flutter - - GoogleMaps (< 3.10) - - GoogleMaps (3.9.0): - - GoogleMaps/Maps (= 3.9.0) - - GoogleMaps/Base (3.9.0) - - GoogleMaps/Maps (3.9.0): + - GoogleMaps (< 9.0) + - GoogleMaps (6.2.1): + - GoogleMaps/Maps (= 6.2.1) + - GoogleMaps/Base (6.2.1) + - GoogleMaps/Maps (6.2.1): - GoogleMaps/Base DEPENDENCIES: - apple_maps_flutter (from `.symlinks/plugins/apple_maps_flutter/ios`) - Flutter (from `Flutter`) - - google_maps_flutter (from `.symlinks/plugins/google_maps_flutter/ios`) + - google_maps_flutter_ios (from `.symlinks/plugins/google_maps_flutter_ios/ios`) SPEC REPOS: trunk: @@ -25,15 +25,15 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/apple_maps_flutter/ios" Flutter: :path: Flutter - google_maps_flutter: - :path: ".symlinks/plugins/google_maps_flutter/ios" + google_maps_flutter_ios: + :path: ".symlinks/plugins/google_maps_flutter_ios/ios" SPEC CHECKSUMS: apple_maps_flutter: c59725efea39e13e703cde52a1d2b14866ad68a8 - Flutter: 434fef37c0980e73bb6479ef766c45957d4b510c - google_maps_flutter: c7f9c73576de1fbe152a227bfd6e6c4ae8088619 - GoogleMaps: 4b5346bddfe6911bb89155d43c903020170523ac + Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 + google_maps_flutter_ios: f135b968a67c05679e0a53538e900b5c174b0d99 + GoogleMaps: 20d7b12be49a14287f797e88e0e31bc4156aaeb4 -PODFILE CHECKSUM: aafe91acc616949ddb318b77800a7f51bffa2a4c +PODFILE CHECKSUM: 4e8f8b2be68aeea4c0d5beb6ff1e79fface1d048 -COCOAPODS: 1.10.1 +COCOAPODS: 1.15.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index 80d5f17..5967552 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -157,7 +157,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1430; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -201,10 +201,12 @@ /* Begin PBXShellScriptBuildPhase section */ 3B06AD1E1E4923F5004D2608 /* Thin Binary */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${TARGET_BUILD_DIR}/${INFOPLIST_PATH}", ); name = "Thin Binary"; outputPaths = ( @@ -271,6 +273,7 @@ }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; + alwaysOutOfDate = 1; buildActionMask = 2147483647; files = ( ); @@ -358,7 +361,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; @@ -432,7 +435,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -481,7 +484,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 9.0; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SUPPORTED_PLATFORMS = iphoneos; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140c..b52b2e6 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ UIViewControllerBasedStatusBarAppearance + CADisableMinimumFrameDurationOnPhone + + UIApplicationSupportsIndirectInputEvents + diff --git a/example/lib/main.dart b/example/lib/main.dart index ba3fd1e..31f9b34 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,23 +1,25 @@ import 'package:flutter/material.dart'; import 'package:platform_maps_flutter/platform_maps_flutter.dart'; -void main() => runApp(MyApp()); +void main() => runApp(const MyApp()); class MyApp extends StatelessWidget { + const MyApp({Key? key}) : super(key: key); + // This widget is the root of your application. @override Widget build(BuildContext context) { - return MaterialApp( + return const MaterialApp( home: MyHomePage(), ); } } class MyHomePage extends StatefulWidget { - MyHomePage({Key? key}) : super(key: key); + const MyHomePage({Key? key}) : super(key: key); @override - _MyHomePageState createState() => _MyHomePageState(); + State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @@ -25,32 +27,30 @@ class _MyHomePageState extends State { Widget build(BuildContext context) { return Scaffold( body: PlatformMap( - initialCameraPosition: CameraPosition( - target: const LatLng(47.6, 8.8796), + initialCameraPosition: const CameraPosition( + target: LatLng(47.6, 8.8796), zoom: 16.0, ), - markers: Set.of( - [ - Marker( - markerId: MarkerId('marker_1'), - position: LatLng(47.6, 8.8796), - consumeTapEvents: true, - infoWindow: InfoWindow( - title: 'PlatformMarker', - snippet: "Hi I'm a Platform Marker", - ), - onTap: () { - print("Marker tapped"); - }, + markers: { + Marker( + markerId: const MarkerId('marker_1'), + position: const LatLng(47.6, 8.8796), + consumeTapEvents: true, + infoWindow: const InfoWindow( + title: 'PlatformMarker', + snippet: "Hi I'm a Platform Marker", ), - ], - ), + onTap: () { + debugPrint("Marker tapped"); + }, + ), + }, mapType: MapType.satellite, - onTap: (location) => print('onTap: $location'), - onCameraMove: (cameraUpdate) => print('onCameraMove: $cameraUpdate'), + onTap: (location) => debugPrint('onTap: $location'), + onCameraMove: (cameraUpdate) => debugPrint('onCameraMove: $cameraUpdate'), compassEnabled: true, onMapCreated: (controller) { - Future.delayed(Duration(seconds: 2)).then( + Future.delayed(const Duration(seconds: 2)).then( (_) { controller.animateCamera( CameraUpdate.newCameraPosition( @@ -64,7 +64,7 @@ class _MyHomePageState extends State { ); controller .getVisibleRegion() - .then((bounds) => print("bounds: ${bounds.toString()}")); + .then((bounds) => debugPrint("bounds: ${bounds.toString()}")); }, ); }, diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c4fa72b..b10bb33 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,19 +1,5 @@ name: flutter_platform_maps_example - -# The following line prevents the package from being accidentally published to -# pub.dev using `pub publish`. This is preferred for private packages. -publish_to: 'none' # Remove this line if you wish to publish to pub.dev - -# The following defines the version and build number for your application. -# A version number is three numbers separated by dots, like 1.2.43 -# followed by an optional build number separated by a +. -# Both the version and the builder number may be overridden in flutter -# build by specifying --build-name and --build-number, respectively. -# In Android, build-name is used as versionName while build-number used as versionCode. -# Read more about Android versioning at https://developer.android.com/studio/publish/versioning -# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. -# Read more about iOS versioning at -# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html +publish_to: 'none' version: 1.0.0+1 environment: @@ -26,52 +12,12 @@ dependencies: platform_maps_flutter: path: ../ - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.2 dev_dependencies: + flutter_lints: ^3.0.1 flutter_test: sdk: flutter -# For information on the generic Dart part of this file, see the -# following page: https://dart.dev/tools/pub/pubspec - -# The following section is specific to Flutter. flutter: - - # The following line ensures that the Material Icons font is - # included with your application, so that you can use the icons in - # the material Icons class. uses-material-design: true - - # To add assets to your application, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/assets-and-images/#resolution-aware. - - # For details regarding adding assets from package dependencies, see - # https://flutter.dev/assets-and-images/#from-packages - - # To add custom fonts to your application, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts from package dependencies, - # see https://flutter.dev/custom-fonts/#from-packages diff --git a/lib/platform_maps_flutter.dart b/lib/platform_maps_flutter.dart index 4668b5a..e16f71a 100644 --- a/lib/platform_maps_flutter.dart +++ b/lib/platform_maps_flutter.dart @@ -1,15 +1,13 @@ library platform_maps_flutter; import 'dart:io'; -import 'dart:typed_data'; -import 'package:apple_maps_flutter/apple_maps_flutter.dart' as appleMaps; -import 'package:flutter/cupertino.dart'; +import 'package:apple_maps_flutter/apple_maps_flutter.dart' as apple_maps; import 'package:flutter/foundation.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:google_maps_flutter/google_maps_flutter.dart' as googleMaps; +import 'package:google_maps_flutter/google_maps_flutter.dart' as google_maps; import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart'; part 'src/bitmap.dart'; diff --git a/lib/src/bitmap.dart b/lib/src/bitmap.dart index 758ea57..dba2d36 100644 --- a/lib/src/bitmap.dart +++ b/lib/src/bitmap.dart @@ -1,4 +1,4 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Defines a bitmap image. For a marker, this class can be used to set the /// image of the marker icon. For a ground overlay, it can be used to set the @@ -12,9 +12,9 @@ class BitmapDescriptor { /// Creates a BitmapDescriptor that refers to the default marker image. static BitmapDescriptor? get defaultMarker { if (Platform.isIOS) { - return BitmapDescriptor._(appleMaps.BitmapDescriptor.defaultAnnotation); + return BitmapDescriptor._(apple_maps.BitmapDescriptor.defaultAnnotation); } else if (Platform.isAndroid) { - return BitmapDescriptor._(googleMaps.BitmapDescriptor.defaultMarker); + return BitmapDescriptor._(google_maps.BitmapDescriptor.defaultMarker); } return null; } @@ -33,14 +33,14 @@ class BitmapDescriptor { }) async { dynamic bitmap; if (Platform.isIOS) { - bitmap = await appleMaps.BitmapDescriptor.fromAssetImage( + bitmap = await apple_maps.BitmapDescriptor.fromAssetImage( configuration, assetName, bundle: bundle, package: package, ); } else if (Platform.isAndroid) { - bitmap = await googleMaps.BitmapDescriptor.fromAssetImage( + bitmap = await google_maps.BitmapDescriptor.fromAssetImage( configuration, assetName, bundle: bundle, @@ -54,8 +54,8 @@ class BitmapDescriptor { /// as PNG. static BitmapDescriptor fromBytes(Uint8List byteData) { var bitmap = Platform.isAndroid - ? googleMaps.BitmapDescriptor.fromBytes(byteData) - : appleMaps.BitmapDescriptor.fromBytes(byteData); + ? google_maps.BitmapDescriptor.fromBytes(byteData) + : apple_maps.BitmapDescriptor.fromBytes(byteData); return BitmapDescriptor._(bitmap); } } diff --git a/lib/src/camera.dart b/lib/src/camera.dart index 1a94c34..aea0754 100644 --- a/lib/src/camera.dart +++ b/lib/src/camera.dart @@ -1,4 +1,4 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// The position of the map "camera", the view point from which the world is /// shown in the map view. Aggregates the camera's [target] geographical @@ -37,26 +37,25 @@ class CameraPosition { /// will be silently clamped to the supported range. final double zoom; - appleMaps.CameraPosition get appleMapsCameraPosition { - return appleMaps.CameraPosition( - target: this.target.appleLatLng, - heading: this.bearing, - pitch: this.tilt, - zoom: this.zoom, + apple_maps.CameraPosition get appleMapsCameraPosition { + return apple_maps.CameraPosition( + target: target.appleLatLng, + heading: bearing, + pitch: tilt, + zoom: zoom, ); } - googleMaps.CameraPosition get googleMapsCameraPosition { - return googleMaps.CameraPosition( - target: this.target.googleLatLng, - bearing: this.bearing, - tilt: this.tilt, - zoom: this.zoom, + google_maps.CameraPosition get googleMapsCameraPosition { + return google_maps.CameraPosition( + target: target.googleLatLng, + bearing: bearing, + tilt: tilt, + zoom: zoom, ); } - static CameraPosition fromAppleMapCameraPosition( - appleMaps.CameraPosition cameraPosition) { + static CameraPosition fromAppleMapCameraPosition(apple_maps.CameraPosition cameraPosition) { return CameraPosition( target: LatLng._fromAppleLatLng(cameraPosition.target), bearing: cameraPosition.heading, @@ -65,8 +64,7 @@ class CameraPosition { ); } - static CameraPosition fromGoogleMapCameraPosition( - googleMaps.CameraPosition cameraPosition) { + static CameraPosition fromGoogleMapCameraPosition(google_maps.CameraPosition cameraPosition) { return CameraPosition( target: LatLng._fromGoogleLatLng(cameraPosition.target), bearing: cameraPosition.bearing, @@ -82,29 +80,27 @@ class CameraUpdate { /// Returns a camera update that moves the camera to the specified position. static newCameraPosition(CameraPosition cameraPosition) { if (Platform.isIOS) { - return appleMaps.CameraUpdate.newCameraPosition( - cameraPosition.appleMapsCameraPosition); + return apple_maps.CameraUpdate.newCameraPosition(cameraPosition.appleMapsCameraPosition); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.newCameraPosition( - cameraPosition.googleMapsCameraPosition); + return google_maps.CameraUpdate.newCameraPosition(cameraPosition.googleMapsCameraPosition); } } /// Returns a camera update that moves the camera target to the specified geographical location. static newLatLng(LatLng latLng) { if (Platform.isIOS) { - return appleMaps.CameraUpdate.newLatLng(latLng.appleLatLng); + return apple_maps.CameraUpdate.newLatLng(latLng.appleLatLng); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.newLatLng(latLng.googleLatLng); + return google_maps.CameraUpdate.newLatLng(latLng.googleLatLng); } } /// Returns a camera update that moves the camera target to the specified geographical location and zoom level. static newLatLngZoom(LatLng latLng, double zoom) { if (Platform.isIOS) { - return appleMaps.CameraUpdate.newLatLngZoom(latLng.appleLatLng, zoom); + return apple_maps.CameraUpdate.newLatLngZoom(latLng.appleLatLng, zoom); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.newLatLngZoom(latLng.googleLatLng, zoom); + return google_maps.CameraUpdate.newLatLngZoom(latLng.googleLatLng, zoom); } } @@ -115,11 +111,9 @@ class CameraUpdate { /// The camera's new tilt and bearing will both be 0.0. static newLatLngBounds(LatLngBounds bounds, double padding) { if (Platform.isIOS) { - return appleMaps.CameraUpdate.newLatLngBounds( - bounds.appleLatLngBounds, padding); + return apple_maps.CameraUpdate.newLatLngBounds(bounds.appleLatLngBounds, padding); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.newLatLngBounds( - bounds.googleLatLngBounds, padding); + return google_maps.CameraUpdate.newLatLngBounds(bounds.googleLatLngBounds, padding); } } @@ -128,9 +122,9 @@ class CameraUpdate { /// should be invariant, if possible, by the movement. static zoomBy(double amount) { if (Platform.isIOS) { - return appleMaps.CameraUpdate.zoomBy(amount); + return apple_maps.CameraUpdate.zoomBy(amount); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.zoomBy(amount); + return google_maps.CameraUpdate.zoomBy(amount); } } @@ -140,9 +134,9 @@ class CameraUpdate { /// Equivalent to the result of calling zoomBy(1.0). static zoomIn() { if (Platform.isIOS) { - return appleMaps.CameraUpdate.zoomIn(); + return apple_maps.CameraUpdate.zoomIn(); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.zoomIn(); + return google_maps.CameraUpdate.zoomIn(); } } @@ -152,18 +146,18 @@ class CameraUpdate { /// Equivalent to the result of calling zoomBy(-1.0). static zoomOut() { if (Platform.isIOS) { - return appleMaps.CameraUpdate.zoomOut(); + return apple_maps.CameraUpdate.zoomOut(); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.zoomOut(); + return google_maps.CameraUpdate.zoomOut(); } } /// Returns a camera update that sets the camera zoom level. static zoomTo(double zoom) { if (Platform.isIOS) { - return appleMaps.CameraUpdate.zoomTo(zoom); + return apple_maps.CameraUpdate.zoomTo(zoom); } else if (Platform.isAndroid) { - return googleMaps.CameraUpdate.zoomTo(zoom); + return google_maps.CameraUpdate.zoomTo(zoom); } } diff --git a/lib/src/cap.dart b/lib/src/cap.dart index f94e780..5d7385f 100644 --- a/lib/src/cap.dart +++ b/lib/src/cap.dart @@ -1,5 +1,5 @@ // Copyright 2019 The Chromium Authors. All rights reserved. -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; enum Cap { /// Cap that is squared off exactly at the start or end vertex of a [Polyline] with solid stroke pattern, @@ -20,23 +20,23 @@ enum Cap { /// Cap that can be applied at the start or end vertex of a [Polyline]. @immutable class _Cap { - static const Map googleMapsCaps = { - Cap.buttCap: googleMaps.Cap.buttCap, - Cap.roundCap: googleMaps.Cap.roundCap, - Cap.squareCap: googleMaps.Cap.squareCap, + static const Map googleMapsCaps = { + Cap.buttCap: google_maps.Cap.buttCap, + Cap.roundCap: google_maps.Cap.roundCap, + Cap.squareCap: google_maps.Cap.squareCap, }; - static const Map appleMapsCaps = { - Cap.buttCap: appleMaps.Cap.buttCap, - Cap.roundCap: appleMaps.Cap.roundCap, - Cap.squareCap: appleMaps.Cap.squareCap, + static const Map appleMapsCaps = { + Cap.buttCap: apple_maps.Cap.buttCap, + Cap.roundCap: apple_maps.Cap.roundCap, + Cap.squareCap: apple_maps.Cap.squareCap, }; - static googleMaps.Cap googlePolylineCap(Cap cap) { + static google_maps.Cap googlePolylineCap(Cap cap) { return googleMapsCaps[cap]!; } - static appleMaps.Cap applePolylineCap(Cap cap) { + static apple_maps.Cap applePolylineCap(Cap cap) { return appleMapsCaps[cap]!; } } diff --git a/lib/src/circle.dart b/lib/src/circle.dart index 544b2ad..25ddb31 100644 --- a/lib/src/circle.dart +++ b/lib/src/circle.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Uniquely identifies a [Circle] among [PlatformMap] circles. /// @@ -10,7 +10,7 @@ part of platform_maps_flutter; @immutable class CircleId { /// Creates an immutable identifier for a [Circle]. - CircleId(this.value); + const CircleId(this.value); /// value of the [CircleId]. final String value; @@ -125,44 +125,44 @@ class Circle { onTap == typedOther.onTap; } - static Set toGoogleMapsCircleSet(Set circles) { - List _circles = []; + static Set toGoogleMapsCircleSet(Set circles) { + List circles0 = []; for (Circle circle in circles) { - _circles.add(circle.googleMapsCircle); + circles0.add(circle.googleMapsCircle); } - return Set.from(_circles); + return Set.from(circles0); } - static Set toAppleMapsCircleSet(Set circles) { - List _circles = []; + static Set toAppleMapsCircleSet(Set circles) { + List circles0 = []; for (Circle circle in circles) { - _circles.add(circle.appleMapsCircle); + circles0.add(circle.appleMapsCircle); } - return Set.from(_circles); + return Set.from(circles0); } - googleMaps.Circle get googleMapsCircle => googleMaps.Circle( - circleId: googleMaps.CircleId(this.circleId.value), - consumeTapEvents: this.consumeTapEvents, - fillColor: this.fillColor, - onTap: this.onTap, - center: this.center.googleLatLng, - radius: this.radius, - strokeColor: this.strokeColor, - strokeWidth: this.strokeWidth, - visible: this.visible, + google_maps.Circle get googleMapsCircle => google_maps.Circle( + circleId: google_maps.CircleId(circleId.value), + consumeTapEvents: consumeTapEvents, + fillColor: fillColor, + onTap: onTap, + center: center.googleLatLng, + radius: radius, + strokeColor: strokeColor, + strokeWidth: strokeWidth, + visible: visible, ); - appleMaps.Circle get appleMapsCircle => appleMaps.Circle( - circleId: appleMaps.CircleId(this.circleId.value), - consumeTapEvents: this.consumeTapEvents, - fillColor: this.fillColor, - onTap: this.onTap, - center: this.center.appleLatLng, - radius: this.radius, - strokeColor: this.strokeColor, - strokeWidth: this.strokeWidth, - visible: this.visible, + apple_maps.Circle get appleMapsCircle => apple_maps.Circle( + circleId: apple_maps.CircleId(circleId.value), + consumeTapEvents: consumeTapEvents, + fillColor: fillColor, + onTap: onTap, + center: center.appleLatLng, + radius: radius, + strokeColor: strokeColor, + strokeWidth: strokeWidth, + visible: visible, ); @override diff --git a/lib/src/controller.dart b/lib/src/controller.dart index 66c10de..cb43fa6 100644 --- a/lib/src/controller.dart +++ b/lib/src/controller.dart @@ -1,14 +1,14 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; class PlatformMapController { - appleMaps.AppleMapController? appleController; - googleMaps.GoogleMapController? googleController; + apple_maps.AppleMapController? appleController; + google_maps.GoogleMapController? googleController; PlatformMapController(dynamic controller) { - if (controller.runtimeType == googleMaps.GoogleMapController) { - this.googleController = controller; - } else if (controller.runtimeType == appleMaps.AppleMapController) { - this.appleController = controller; + if (controller.runtimeType == google_maps.GoogleMapController) { + googleController = controller; + } else if (controller.runtimeType == apple_maps.AppleMapController) { + appleController = controller; } } @@ -22,11 +22,9 @@ class PlatformMapController { /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. Future showMarkerInfoWindow(MarkerId markerId) { if (Platform.isAndroid) { - return googleController! - .showMarkerInfoWindow(markerId.googleMapsMarkerId); + return googleController!.showMarkerInfoWindow(markerId.googleMapsMarkerId); } else if (Platform.isIOS) { - return appleController! - .showMarkerInfoWindow(markerId.appleMapsAnnoationId); + return appleController!.showMarkerInfoWindow(markerId.appleMapsAnnoationId); } throw ('Platform not supported.'); } @@ -41,11 +39,9 @@ class PlatformMapController { /// * [isMarkerInfoWindowShown] to check if the Info Window is showing. Future hideMarkerInfoWindow(MarkerId markerId) { if (Platform.isAndroid) { - return googleController! - .hideMarkerInfoWindow(markerId.googleMapsMarkerId); + return googleController!.hideMarkerInfoWindow(markerId.googleMapsMarkerId); } else if (Platform.isIOS) { - return appleController! - .hideMarkerInfoWindow(markerId.appleMapsAnnoationId); + return appleController!.hideMarkerInfoWindow(markerId.appleMapsAnnoationId); } throw ('Platform not supported.'); } @@ -60,12 +56,9 @@ class PlatformMapController { /// * [hideMarkerInfoWindow] to hide the Info Window. Future isMarkerInfoWindowShown(MarkerId markerId) async { if (Platform.isAndroid) { - return googleController! - .isMarkerInfoWindowShown(markerId.googleMapsMarkerId); + return googleController!.isMarkerInfoWindowShown(markerId.googleMapsMarkerId); } else if (Platform.isIOS) { - return await appleController! - .isMarkerInfoWindowShown(markerId.appleMapsAnnoationId) ?? - false; + return await appleController!.isMarkerInfoWindowShown(markerId.appleMapsAnnoationId) ?? false; } throw ('Platform not supported.'); } @@ -76,9 +69,9 @@ class PlatformMapController { /// platform side. Future animateCamera(cameraUpdate) async { if (Platform.isIOS) { - return this.appleController!.animateCamera(cameraUpdate); + return appleController!.animateCamera(cameraUpdate); } else if (Platform.isAndroid) { - return this.googleController!.animateCamera(cameraUpdate); + return googleController!.animateCamera(cameraUpdate); } throw ('Platform not supported.'); } @@ -89,33 +82,32 @@ class PlatformMapController { /// platform side. Future moveCamera(cameraUpdate) async { if (Platform.isIOS) { - return this.appleController!.moveCamera(cameraUpdate); + return appleController!.moveCamera(cameraUpdate); } else if (Platform.isAndroid) { - return this.googleController!.moveCamera(cameraUpdate); + return googleController!.moveCamera(cameraUpdate); } } /// Return [LatLngBounds] defining the region that is visible in a map. Future getVisibleRegion() async { - late LatLngBounds _bounds; + late LatLngBounds bounds; if (Platform.isIOS) { - appleMaps.LatLngBounds appleBounds = - await this.appleController!.getVisibleRegion(); - _bounds = LatLngBounds._fromAppleLatLngBounds(appleBounds); + apple_maps.LatLngBounds appleBounds = await appleController!.getVisibleRegion(); + bounds = LatLngBounds._fromAppleLatLngBounds(appleBounds); } else if (Platform.isAndroid) { - googleMaps.LatLngBounds googleBounds = - await this.googleController!.getVisibleRegion(); - _bounds = LatLngBounds._fromGoogleLatLngBounds(googleBounds); + google_maps.LatLngBounds googleBounds = await googleController!.getVisibleRegion(); + bounds = LatLngBounds._fromGoogleLatLngBounds(googleBounds); } - return _bounds; + return bounds; } /// Returns the image bytes of the map Future takeSnapshot() async { if (Platform.isIOS) { - return this.appleController!.takeSnapshot(); + return appleController!.takeSnapshot(); } else if (Platform.isAndroid) { - return this.googleController!.takeSnapshot(); + return googleController!.takeSnapshot(); } + throw UnsupportedError('platform_maps only supports iOS and Android'); } } diff --git a/lib/src/joint_type.dart b/lib/src/joint_type.dart index 27e5d24..a307dc6 100644 --- a/lib/src/joint_type.dart +++ b/lib/src/joint_type.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Joint types for [Polyline]. @immutable @@ -12,16 +12,16 @@ class JointType { /// The value representing the [JointType] on the sdk. final int value; - static const List googleMapsJointTypes = const [ - googleMaps.JointType.mitered, - googleMaps.JointType.bevel, - googleMaps.JointType.round, + static const List googleMapsJointTypes = [ + google_maps.JointType.mitered, + google_maps.JointType.bevel, + google_maps.JointType.round, ]; - static const List appleMapsJointTypes = const [ - appleMaps.JointType.mitered, - appleMaps.JointType.bevel, - appleMaps.JointType.round, + static const List appleMapsJointTypes = [ + apple_maps.JointType.mitered, + apple_maps.JointType.bevel, + apple_maps.JointType.round, ]; /// Mitered joint, with fixed pointed extrusion equal to half the stroke width on the outside of the joint. @@ -39,11 +39,11 @@ class JointType { /// Constant Value: 2 static const JointType round = JointType._(2); - static googleMaps.JointType getGoogleMapsJointType(JointType jointType) { + static google_maps.JointType getGoogleMapsJointType(JointType jointType) { return googleMapsJointTypes[jointType.value]; } - static appleMaps.JointType getAppleMapsJointType(JointType jointType) { + static apple_maps.JointType getAppleMapsJointType(JointType jointType) { return appleMapsJointTypes[jointType.value]; } } diff --git a/lib/src/location.dart b/lib/src/location.dart index a2537be..2ea7d7b 100644 --- a/lib/src/location.dart +++ b/lib/src/location.dart @@ -1,4 +1,4 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// A pair of latitude and longitude coordinates, stored as degrees. class LatLng { @@ -10,8 +10,7 @@ class LatLng { /// The longitude is normalized to the half-open interval from -180.0 /// (inclusive) to +180.0 (exclusive) const LatLng(double latitude, double longitude) - : latitude = - (latitude < -90.0 ? -90.0 : (90.0 < latitude ? 90.0 : latitude)), + : latitude = (latitude < -90.0 ? -90.0 : (90.0 < latitude ? 90.0 : latitude)), longitude = (longitude + 180.0) % 360.0 - 180.0; /// The latitude in degrees between -90.0 and 90.0, both inclusive. @@ -23,36 +22,35 @@ class LatLng { @override String toString() => '$runtimeType($latitude, $longitude)'; - static LatLng _fromAppleLatLng(appleMaps.LatLng latLng) => + static LatLng _fromAppleLatLng(apple_maps.LatLng latLng) => LatLng(latLng.latitude, latLng.longitude); - static LatLng _fromGoogleLatLng(googleMaps.LatLng latLng) => + static LatLng _fromGoogleLatLng(google_maps.LatLng latLng) => LatLng(latLng.latitude, latLng.longitude); - appleMaps.LatLng get appleLatLng => appleMaps.LatLng( - this.latitude, - this.longitude, + apple_maps.LatLng get appleLatLng => apple_maps.LatLng( + latitude, + longitude, ); - googleMaps.LatLng get googleLatLng => googleMaps.LatLng( - this.latitude, - this.longitude, + google_maps.LatLng get googleLatLng => google_maps.LatLng( + latitude, + longitude, ); - static List googleMapsLatLngsFromList( - List latlngs) { - List googleMapsLatLngs = []; - latlngs.forEach((LatLng latlng) { + static List googleMapsLatLngsFromList(List latlngs) { + List googleMapsLatLngs = []; + for (var latlng in latlngs) { googleMapsLatLngs.add(latlng.googleLatLng); - }); + } return googleMapsLatLngs; } - static List appleMapsLatLngsFromList(List latlngs) { - List appleMapsLatLngs = []; - latlngs.forEach((LatLng latlng) { + static List appleMapsLatLngsFromList(List latlngs) { + List appleMapsLatLngs = []; + for (var latlng in latlngs) { appleMapsLatLngs.add(latlng.appleLatLng); - }); + } return appleMapsLatLngs; } } @@ -65,14 +63,12 @@ class LatLngBounds { LatLngBounds({required this.southwest, required this.northeast}) : assert(southwest.latitude <= northeast.latitude); - static LatLngBounds _fromAppleLatLngBounds(appleMaps.LatLngBounds bounds) => - LatLngBounds( + static LatLngBounds _fromAppleLatLngBounds(apple_maps.LatLngBounds bounds) => LatLngBounds( southwest: LatLng._fromAppleLatLng(bounds.southwest), northeast: LatLng._fromAppleLatLng(bounds.northeast), ); - static LatLngBounds _fromGoogleLatLngBounds(googleMaps.LatLngBounds bounds) => - LatLngBounds( + static LatLngBounds _fromGoogleLatLngBounds(google_maps.LatLngBounds bounds) => LatLngBounds( southwest: LatLng._fromGoogleLatLng(bounds.southwest), northeast: LatLng._fromGoogleLatLng(bounds.northeast), ); @@ -83,19 +79,18 @@ class LatLngBounds { /// The northeast corner of the rectangle. final LatLng northeast; - appleMaps.LatLngBounds get appleLatLngBounds => appleMaps.LatLngBounds( - southwest: this.southwest.appleLatLng, - northeast: this.northeast.appleLatLng, + apple_maps.LatLngBounds get appleLatLngBounds => apple_maps.LatLngBounds( + southwest: southwest.appleLatLng, + northeast: northeast.appleLatLng, ); - googleMaps.LatLngBounds get googleLatLngBounds => googleMaps.LatLngBounds( - southwest: this.southwest.googleLatLng, - northeast: this.northeast.googleLatLng, + google_maps.LatLngBounds get googleLatLngBounds => google_maps.LatLngBounds( + southwest: southwest.googleLatLng, + northeast: northeast.googleLatLng, ); bool contains(LatLng point) { - return _containsLatitude(point.latitude) && - _containsLongitude(point.longitude); + return _containsLatitude(point.latitude) && _containsLongitude(point.longitude); } bool _containsLatitude(double lat) { diff --git a/lib/src/marker.dart b/lib/src/marker.dart index c2d7e31..1fcda3f 100644 --- a/lib/src/marker.dart +++ b/lib/src/marker.dart @@ -1,4 +1,4 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Text labels for a [Marker] info window. class InfoWindow { @@ -28,18 +28,18 @@ class InfoWindow { /// onTap callback for this [InfoWindow]. final VoidCallback? onTap; - appleMaps.InfoWindow get appleMapsInfoWindow => appleMaps.InfoWindow( - anchor: this.anchor ?? Offset(0, 0), - onTap: this.onTap, - snippet: this.snippet, - title: this.title, + apple_maps.InfoWindow get appleMapsInfoWindow => apple_maps.InfoWindow( + anchor: anchor ?? const Offset(0, 0), + onTap: onTap, + snippet: snippet, + title: title, ); - googleMaps.InfoWindow get googleMapsInfoWindow => googleMaps.InfoWindow( - anchor: this.anchor ?? Offset(0, 0), - onTap: this.onTap, - snippet: this.snippet, - title: this.title, + google_maps.InfoWindow get googleMapsInfoWindow => google_maps.InfoWindow( + anchor: anchor ?? const Offset(0, 0), + onTap: onTap, + snippet: snippet, + title: title, ); /// Creates a new [InfoWindow] object whose values are the same as this instance, @@ -64,17 +64,17 @@ class InfoWindow { /// This does not have to be globally unique, only unique among the list. @immutable class MarkerId { - MarkerId(this.value); + const MarkerId(this.value); /// value of the [MarkerId]. final String value; - appleMaps.AnnotationId get appleMapsAnnoationId => appleMaps.AnnotationId( - this.value, + apple_maps.AnnotationId get appleMapsAnnoationId => apple_maps.AnnotationId( + value, ); - googleMaps.MarkerId get googleMapsMarkerId => googleMaps.MarkerId( - this.value, + google_maps.MarkerId get googleMapsMarkerId => google_maps.MarkerId( + value, ); } @@ -154,91 +154,81 @@ class Marker { final ValueChanged? onDragEnd; - appleMaps.Annotation get appleMapsAnnotation => appleMaps.Annotation( - annotationId: this.markerId.appleMapsAnnoationId, - alpha: this.alpha, - anchor: this.anchor, - draggable: this.draggable, - infoWindow: this.infoWindow.appleMapsInfoWindow, - onTap: this.onTap, - icon: this.icon?.bitmapDescriptor ?? - BitmapDescriptor.defaultMarker?.bitmapDescriptor, - visible: this.visible, - onDragEnd: this.onDragEnd != null - ? (appleMaps.LatLng latLng) => - _onAppleAnnotationDragEnd(latLng, this.onDragEnd) + apple_maps.Annotation get appleMapsAnnotation => apple_maps.Annotation( + annotationId: markerId.appleMapsAnnoationId, + alpha: alpha, + anchor: anchor, + draggable: draggable, + infoWindow: infoWindow.appleMapsInfoWindow, + onTap: onTap, + icon: icon?.bitmapDescriptor ?? BitmapDescriptor.defaultMarker?.bitmapDescriptor, + visible: visible, + onDragEnd: onDragEnd != null + ? (apple_maps.LatLng latLng) => _onAppleAnnotationDragEnd(latLng, onDragEnd) : null, - position: this.position.appleLatLng, + position: position.appleLatLng, ); - googleMaps.Marker get googleMapsMarker => googleMaps.Marker( - markerId: this.markerId.googleMapsMarkerId, - alpha: this.alpha, - anchor: this.anchor, - draggable: this.draggable, - infoWindow: this.infoWindow.googleMapsInfoWindow, - onTap: this.onTap, - icon: this.icon?.bitmapDescriptor ?? - BitmapDescriptor.defaultMarker?.bitmapDescriptor, - visible: this.visible, - onDragEnd: this.onDragEnd != null - ? (googleMaps.LatLng latLng) => - _onGoogleMarkerDragEnd(latLng, this.onDragEnd) + google_maps.Marker get googleMapsMarker => google_maps.Marker( + markerId: markerId.googleMapsMarkerId, + alpha: alpha, + anchor: anchor, + draggable: draggable, + infoWindow: infoWindow.googleMapsInfoWindow, + onTap: onTap, + icon: icon?.bitmapDescriptor ?? BitmapDescriptor.defaultMarker?.bitmapDescriptor, + visible: visible, + onDragEnd: onDragEnd != null + ? (google_maps.LatLng latLng) => _onGoogleMarkerDragEnd(latLng, onDragEnd) : null, - position: this.position.googleLatLng, + position: position.googleLatLng, ); - static appleMaps.Annotation appleMapsAnnotationFromMarker(Marker marker) => - appleMaps.Annotation( + static apple_maps.Annotation appleMapsAnnotationFromMarker(Marker marker) => + apple_maps.Annotation( annotationId: marker.markerId.appleMapsAnnoationId, alpha: marker.alpha, anchor: marker.anchor, draggable: marker.draggable, infoWindow: marker.infoWindow.appleMapsInfoWindow, onTap: marker.onTap, - icon: marker.icon?.bitmapDescriptor ?? - BitmapDescriptor.defaultMarker?.bitmapDescriptor, + icon: marker.icon?.bitmapDescriptor ?? BitmapDescriptor.defaultMarker?.bitmapDescriptor, visible: marker.visible, onDragEnd: marker.onDragEnd != null - ? (appleMaps.LatLng latLng) => - _onAppleAnnotationDragEnd(latLng, marker.onDragEnd) + ? (apple_maps.LatLng latLng) => _onAppleAnnotationDragEnd(latLng, marker.onDragEnd) : null, position: marker.position.appleLatLng, ); - static googleMaps.Marker googleMapsMarkerFromMarker(Marker marker) => - googleMaps.Marker( + static google_maps.Marker googleMapsMarkerFromMarker(Marker marker) => google_maps.Marker( markerId: marker.markerId.googleMapsMarkerId, alpha: marker.alpha, anchor: marker.anchor, draggable: marker.draggable, infoWindow: marker.infoWindow.googleMapsInfoWindow, onTap: marker.onTap, - icon: marker.icon?.bitmapDescriptor ?? - BitmapDescriptor.defaultMarker?.bitmapDescriptor, + icon: marker.icon?.bitmapDescriptor ?? BitmapDescriptor.defaultMarker?.bitmapDescriptor, visible: marker.visible, onDragEnd: marker.onDragEnd != null - ? (googleMaps.LatLng latLng) => - _onGoogleMarkerDragEnd(latLng, marker.onDragEnd) + ? (google_maps.LatLng latLng) => _onGoogleMarkerDragEnd(latLng, marker.onDragEnd) : null, position: marker.position.googleLatLng, ); - static Set toAppleMapsAnnotationSet( - Set markers) { - List _annotations = []; + static Set toAppleMapsAnnotationSet(Set markers) { + List annotations = []; for (Marker marker in markers) { - _annotations.add(appleMapsAnnotationFromMarker(marker)); + annotations.add(appleMapsAnnotationFromMarker(marker)); } - return Set.from(_annotations); + return Set.from(annotations); } - static Set toGoogleMapsMarkerSet(Set markers) { - List _markers = []; + static Set toGoogleMapsMarkerSet(Set markers) { + List markers0 = []; for (Marker marker in markers) { - _markers.add(googleMapsMarkerFromMarker(marker)); + markers0.add(googleMapsMarkerFromMarker(marker)); } - return Set.from(_markers); + return Set.from(markers0); } Marker copyWith({ @@ -266,12 +256,11 @@ class Marker { ); } - static _onGoogleMarkerDragEnd(googleMaps.LatLng latLng, Function? onDragEnd) { + static _onGoogleMarkerDragEnd(google_maps.LatLng latLng, Function? onDragEnd) { onDragEnd?.call(LatLng._fromGoogleLatLng(latLng)); } - static _onAppleAnnotationDragEnd( - appleMaps.LatLng latLng, Function? onDragEnd) { + static _onAppleAnnotationDragEnd(apple_maps.LatLng latLng, Function? onDragEnd) { onDragEnd?.call(LatLng._fromAppleLatLng(latLng)); } } diff --git a/lib/src/pattern_item.dart b/lib/src/pattern_item.dart index 0f01b28..376d807 100644 --- a/lib/src/pattern_item.dart +++ b/lib/src/pattern_item.dart @@ -1,4 +1,4 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Item used in the stroke pattern for a Polyline. @immutable @@ -23,46 +23,44 @@ class PatternItem { return PatternItem._(['gap', length]); } - static googleMaps.PatternItem _googleMapsPatternItem( - PatternItem patternItem) { + static google_maps.PatternItem _googleMapsPatternItem(PatternItem patternItem) { if (patternItem._json[0] == 'dash') { - return googleMaps.PatternItem.dash(patternItem._json[1]); + return google_maps.PatternItem.dash(patternItem._json[1]); } else if (patternItem._json[0] == 'gap') { - return googleMaps.PatternItem.gap(patternItem._json[1]); + return google_maps.PatternItem.gap(patternItem._json[1]); } - return googleMaps.PatternItem.dot; + return google_maps.PatternItem.dot; } - static appleMaps.PatternItem _appleMapsPatternItem(PatternItem patternItem) { + static apple_maps.PatternItem _appleMapsPatternItem(PatternItem patternItem) { if (patternItem._json[0] == 'dash') { - return appleMaps.PatternItem.dash(patternItem._json[1]); + return apple_maps.PatternItem.dash(patternItem._json[1]); } else if (patternItem._json[0] == 'gap') { - return appleMaps.PatternItem.gap(patternItem._json[1]); + return apple_maps.PatternItem.gap(patternItem._json[1]); } - return appleMaps.PatternItem.dot; + return apple_maps.PatternItem.dot; } final dynamic _json; - static List getGoogleMapsPatternItemList( + static List getGoogleMapsPatternItemList( List patternItems) { - List googleMapsPatternItems = []; - patternItems.forEach((PatternItem patternItem) { + List googleMapsPatternItems = []; + for (var patternItem in patternItems) { googleMapsPatternItems.add( _googleMapsPatternItem(patternItem), ); - }); + } return googleMapsPatternItems; } - static List getAppleMapsPatternItemList( - List patternItems) { - List appleMapsPatternItems = []; - patternItems.forEach((PatternItem patternItem) { + static List getAppleMapsPatternItemList(List patternItems) { + List appleMapsPatternItems = []; + for (var patternItem in patternItems) { appleMapsPatternItems.add( _appleMapsPatternItem(patternItem), ); - }); + } return appleMapsPatternItems; } } diff --git a/lib/src/platform_maps.dart b/lib/src/platform_maps.dart index 860ed81..3177939 100644 --- a/lib/src/platform_maps.dart +++ b/lib/src/platform_maps.dart @@ -1,8 +1,8 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; -typedef void MapCreatedCallback(PlatformMapController controller); +typedef MapCreatedCallback = void Function(PlatformMapController controller); -typedef void CameraPositionCallback(CameraPosition position); +typedef CameraPositionCallback = void Function(CameraPosition position); class PlatformMap extends StatefulWidget { const PlatformMap({ @@ -164,16 +164,15 @@ class PlatformMap extends StatefulWidget { /// were not claimed by any other gesture recognizer. final Set> gestureRecognizers; @override - _PlatformMapState createState() => _PlatformMapState(); + State createState() => _PlatformMapState(); } class _PlatformMapState extends State { @override Widget build(BuildContext context) { if (Platform.isAndroid) { - return googleMaps.GoogleMap( - initialCameraPosition: - widget.initialCameraPosition.googleMapsCameraPosition, + return google_maps.GoogleMap( + initialCameraPosition: widget.initialCameraPosition.googleMapsCameraPosition, compassEnabled: widget.compassEnabled, mapType: _getGoogleMapType(), padding: widget.padding, @@ -196,13 +195,11 @@ class _PlatformMapState extends State { onTap: _onTap, onLongPress: _onLongPress, trafficEnabled: widget.trafficEnabled, - minMaxZoomPreference: - widget.minMaxZoomPreference.googleMapsZoomPreference, + minMaxZoomPreference: widget.minMaxZoomPreference.googleMapsZoomPreference, ); } else if (Platform.isIOS) { - return appleMaps.AppleMap( - initialCameraPosition: - widget.initialCameraPosition.appleMapsCameraPosition, + return apple_maps.AppleMap( + initialCameraPosition: widget.initialCameraPosition.appleMapsCameraPosition, compassEnabled: widget.compassEnabled, mapType: _getAppleMapType(), padding: widget.padding, @@ -224,11 +221,10 @@ class _PlatformMapState extends State { onTap: _onTap, onLongPress: _onLongPress, trafficEnabled: widget.trafficEnabled, - minMaxZoomPreference: - widget.minMaxZoomPreference.appleMapsZoomPreference, + minMaxZoomPreference: widget.minMaxZoomPreference.appleMapsZoomPreference, ); } else { - return Text("Platform not yet implemented"); + return const Text("Platform not yet implemented"); } } @@ -240,13 +236,13 @@ class _PlatformMapState extends State { if (Platform.isIOS) { widget.onCameraMove?.call( CameraPosition.fromAppleMapCameraPosition( - cameraPosition as appleMaps.CameraPosition, + cameraPosition as apple_maps.CameraPosition, ), ); } else if (Platform.isAndroid) { widget.onCameraMove?.call( CameraPosition.fromGoogleMapCameraPosition( - cameraPosition as googleMaps.CameraPosition, + cameraPosition as google_maps.CameraPosition, ), ); } @@ -254,42 +250,39 @@ class _PlatformMapState extends State { void _onTap(dynamic position) { if (Platform.isIOS) { - widget.onTap?.call(LatLng._fromAppleLatLng(position as appleMaps.LatLng)); + widget.onTap?.call(LatLng._fromAppleLatLng(position as apple_maps.LatLng)); } else if (Platform.isAndroid) { - widget.onTap - ?.call(LatLng._fromGoogleLatLng(position as googleMaps.LatLng)); + widget.onTap?.call(LatLng._fromGoogleLatLng(position as google_maps.LatLng)); } } void _onLongPress(dynamic position) { if (Platform.isIOS) { - widget.onLongPress - ?.call(LatLng._fromAppleLatLng(position as appleMaps.LatLng)); + widget.onLongPress?.call(LatLng._fromAppleLatLng(position as apple_maps.LatLng)); } else if (Platform.isAndroid) { - widget.onLongPress - ?.call(LatLng._fromGoogleLatLng(position as googleMaps.LatLng)); + widget.onLongPress?.call(LatLng._fromGoogleLatLng(position as google_maps.LatLng)); } } - appleMaps.MapType _getAppleMapType() { + apple_maps.MapType _getAppleMapType() { if (widget.mapType == MapType.normal) { - return appleMaps.MapType.standard; + return apple_maps.MapType.standard; } else if (widget.mapType == MapType.satellite) { - return appleMaps.MapType.satellite; + return apple_maps.MapType.satellite; } else if (widget.mapType == MapType.hybrid) { - return appleMaps.MapType.hybrid; + return apple_maps.MapType.hybrid; } - return appleMaps.MapType.standard; + return apple_maps.MapType.standard; } - googleMaps.MapType _getGoogleMapType() { + google_maps.MapType _getGoogleMapType() { if (widget.mapType == MapType.normal) { - return googleMaps.MapType.normal; + return google_maps.MapType.normal; } else if (widget.mapType == MapType.satellite) { - return googleMaps.MapType.satellite; + return google_maps.MapType.satellite; } else if (widget.mapType == MapType.hybrid) { - return googleMaps.MapType.hybrid; + return google_maps.MapType.hybrid; } - return googleMaps.MapType.normal; + return google_maps.MapType.normal; } } diff --git a/lib/src/polygon.dart b/lib/src/polygon.dart index 843ffed..9cb24b1 100644 --- a/lib/src/polygon.dart +++ b/lib/src/polygon.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Uniquely identifies a [Polygon] among [PlatformMap] polygons. /// @@ -10,7 +10,7 @@ part of platform_maps_flutter; @immutable class PolygonId { /// Creates an immutable identifier for a [Polygon]. - PolygonId(this.value); + const PolygonId(this.value); /// value of the [PolygonId]. final String value; @@ -125,41 +125,41 @@ class Polygon { @override int get hashCode => polygonId.hashCode; - static Set toGoogleMapsPolygonSet(Set polygons) { - List _polygons = []; + static Set toGoogleMapsPolygonSet(Set polygons) { + List polygons0 = []; for (Polygon polygon in polygons) { - _polygons.add(polygon.googleMapsPolygon); + polygons0.add(polygon.googleMapsPolygon); } - return Set.from(_polygons); + return Set.from(polygons0); } - static Set toAppleMapsPolygonSet(Set polygons) { - List _polygons = []; + static Set toAppleMapsPolygonSet(Set polygons) { + List polygons0 = []; for (Polygon polygon in polygons) { - _polygons.add(polygon.appleMapsPolygon); + polygons0.add(polygon.appleMapsPolygon); } - return Set.from(_polygons); + return Set.from(polygons0); } - googleMaps.Polygon get googleMapsPolygon => googleMaps.Polygon( - polygonId: googleMaps.PolygonId(this.polygonId.value), - consumeTapEvents: this.consumeTapEvents, - fillColor: this.fillColor, - onTap: this.onTap, - points: LatLng.googleMapsLatLngsFromList(this.points), - strokeColor: this.strokeColor, - strokeWidth: this.strokeWidth, - visible: this.visible, + google_maps.Polygon get googleMapsPolygon => google_maps.Polygon( + polygonId: google_maps.PolygonId(polygonId.value), + consumeTapEvents: consumeTapEvents, + fillColor: fillColor, + onTap: onTap, + points: LatLng.googleMapsLatLngsFromList(points), + strokeColor: strokeColor, + strokeWidth: strokeWidth, + visible: visible, ); - appleMaps.Polygon get appleMapsPolygon => appleMaps.Polygon( - polygonId: appleMaps.PolygonId(this.polygonId.value), - consumeTapEvents: this.consumeTapEvents, - fillColor: this.fillColor, - onTap: this.onTap, - points: LatLng.appleMapsLatLngsFromList(this.points), - strokeColor: this.strokeColor, - strokeWidth: this.strokeWidth, - visible: this.visible, + apple_maps.Polygon get appleMapsPolygon => apple_maps.Polygon( + polygonId: apple_maps.PolygonId(polygonId.value), + consumeTapEvents: consumeTapEvents, + fillColor: fillColor, + onTap: onTap, + points: LatLng.appleMapsLatLngsFromList(points), + strokeColor: strokeColor, + strokeWidth: strokeWidth, + visible: visible, ); } diff --git a/lib/src/polyline.dart b/lib/src/polyline.dart index bf3724b..aacc7aa 100644 --- a/lib/src/polyline.dart +++ b/lib/src/polyline.dart @@ -1,23 +1,23 @@ -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Uniquely identifies a [Polyline] among [AppleMap] polylines. /// /// This does not have to be globally unique, only unique among the list. @immutable class PolylineId { - PolylineId(this.value); + const PolylineId(this.value); /// value of the [PolylineId]. final String value; - googleMaps.PolylineId googleMapsPolylineId() { - return googleMaps.PolylineId( + google_maps.PolylineId googleMapsPolylineId() { + return google_maps.PolylineId( value, ); } - appleMaps.PolylineId appleMapsPolylineId() { - return appleMaps.PolylineId( + apple_maps.PolylineId appleMapsPolylineId() { + return apple_maps.PolylineId( value, ); } @@ -106,12 +106,11 @@ class Polyline { /// Callbacks to receive tap events for polyline placed on this map. final VoidCallback? onTap; - static Set toGoogleMapsPolylines( - Set polylines) { - Set googleMapsPolylines = Set(); - polylines.forEach((Polyline polyline) { + static Set toGoogleMapsPolylines(Set polylines) { + Set googleMapsPolylines = {}; + for (var polyline in polylines) { googleMapsPolylines.add( - googleMaps.Polyline( + google_maps.Polyline( polylineId: polyline.polylineId.googleMapsPolylineId(), color: polyline.color, consumeTapEvents: polyline.consumeTapEvents, @@ -125,15 +124,15 @@ class Polyline { width: polyline.width, ), ); - }); + } return googleMapsPolylines; } - static Set toAppleMapsPolylines(Set polylines) { - Set appleMapsPolylines = Set(); - polylines.forEach((Polyline polyline) { + static Set toAppleMapsPolylines(Set polylines) { + Set appleMapsPolylines = {}; + for (var polyline in polylines) { appleMapsPolylines.add( - appleMaps.Polyline( + apple_maps.Polyline( polylineId: polyline.polylineId.appleMapsPolylineId(), color: polyline.color, consumeTapEvents: polyline.consumeTapEvents, @@ -146,7 +145,7 @@ class Polyline { width: polyline.width, ), ); - }); + } return appleMapsPolylines; } diff --git a/lib/src/ui.dart b/lib/src/ui.dart index 815c228..6d1419c 100644 --- a/lib/src/ui.dart +++ b/lib/src/ui.dart @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -part of platform_maps_flutter; +part of '../platform_maps_flutter.dart'; /// Type of map tiles to display. enum MapType { @@ -31,11 +31,11 @@ class MinMaxZoomPreference { /// The preferred maximum zoom level or null, if unbounded from above. final double? maxZoom; - appleMaps.MinMaxZoomPreference get appleMapsZoomPreference => - appleMaps.MinMaxZoomPreference(this.maxZoom, this.maxZoom); + apple_maps.MinMaxZoomPreference get appleMapsZoomPreference => + apple_maps.MinMaxZoomPreference(maxZoom, maxZoom); - googleMaps.MinMaxZoomPreference get googleMapsZoomPreference => - googleMaps.MinMaxZoomPreference(this.maxZoom, this.maxZoom); + google_maps.MinMaxZoomPreference get googleMapsZoomPreference => + google_maps.MinMaxZoomPreference(maxZoom, maxZoom); /// Converts this object to something serializable in JSON. dynamic toJson() => [minZoom, maxZoom]; diff --git a/pubspec.yaml b/pubspec.yaml index 123d161..3477e44 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ repository: https://github.com/LuisThein/platform_maps_flutter issue_tracker: https://github.com/LuisThein/platform_maps_flutter/issues environment: - sdk: '>=2.12.0 <3.0.0' + sdk: '>=2.17.0 <4.0.0' dependencies: flutter: @@ -17,6 +17,6 @@ dependencies: apple_maps_flutter: ^1.0.1 dev_dependencies: + flutter_lints: ^3.0.1 flutter_test: sdk: flutter - pedantic: ^1.11.0