Skip to content

Commit

Permalink
Null safety (cherry-pick from upstream) (#31)
Browse files Browse the repository at this point in the history
* Cherry-pick and adapt null safety from upstream

Co-Authored-By: morvagergely <[email protected]>

* Fix requestMyLocationLatLng in the platform interface (#697)

It was crashing for me with the following error:
```
flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: type '_InternalLinkedHashMap<Object?, Object?>' is not a subtype of type 'Map<Object, Object>'
```

No reason to use <Object, Object> types instead of <dynamic, dynamic> as
used everywhere else

* Fix  Warning: Operand of null-aware operation '!' has type 'Locale' which excludes null. (#676)

* Update LICENCE regarding cherry-picks

* Formatting

* Fix linter hints (unnecessary imports)

* Fix linter hint (another unnecessary import)

Co-authored-by: morvagergely <[email protected]>
Co-authored-by: shroff <[email protected]>
Co-authored-by: Tomás Weigenast <[email protected]>
  • Loading branch information
4 people authored Oct 26, 2021
1 parent 6c9b75f commit 2a37ff7
Show file tree
Hide file tree
Showing 49 changed files with 616 additions and 694 deletions.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------
This project was forked from (and therefore contains a lot of modified and unmodified code from) https://github.com/tobrun/flutter-mapbox-gl which at the time of the fork (March 6th, 2021) contained the following LICENSE file:
(Additionally more changes / code was later cherry-picked / ported from that repository (https://github.com/tobrun/flutter-mapbox-gl), while the license continued to be the same as at the time of the fork, which is:)
------------------------------------------------------------------------------------------------------

flutter-mapbox-gl copyright (c) 2018, Mapbox.
Expand Down
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ rootProject.allprojects {
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
compileSdkVersion 29

defaultConfig {
minSdkVersion 20
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
lintOptions {
disable 'InvalidPackage'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.constants.MapboxConstants;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
import com.mapbox.mapboxsdk.geometry.LatLngQuad;
Expand Down Expand Up @@ -1233,13 +1234,8 @@ public void setTiltGesturesEnabled(boolean tiltGesturesEnabled) {

@Override
public void setMinMaxZoomPreference(Float min, Float max) {
//mapboxMap.resetMinMaxZoomPreference();
if (min != null) {
mapboxMap.setMinZoomPreference(min);
}
if (max != null) {
mapboxMap.setMaxZoomPreference(max);
}
mapboxMap.setMinZoomPreference(min != null ? min : MapboxConstants.MINIMUM_ZOOM);
mapboxMap.setMaxZoomPreference(max != null ? max : MapboxConstants.MAXIMUM_ZOOM);
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 29

lintOptions {
disable 'InvalidPackage'
Expand All @@ -39,6 +39,7 @@ android {
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}

buildTypes {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/animate_camera.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AnimateCamera extends StatefulWidget {
}

class AnimateCameraState extends State<AnimateCamera> {
MaplibreMapController mapController;
late MaplibreMapController mapController;

void _onMapCreated(MaplibreMapController controller) {
mapController = controller;
Expand Down
4 changes: 2 additions & 2 deletions example/lib/annotation_order_maps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class AnnotationOrderBody extends StatefulWidget {
}

class _AnnotationOrderBodyState extends State<AnnotationOrderBody> {
MaplibreMapController controllerOne;
MaplibreMapController controllerTwo;
late MaplibreMapController controllerOne;
late MaplibreMapController controllerTwo;

final LatLng center = const LatLng(36.580664, 32.5563837);

Expand Down
15 changes: 8 additions & 7 deletions example/lib/custom_marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CustomMarker extends StatefulWidget {
class CustomMarkerState extends State<CustomMarker> {
final Random _rnd = new Random();

MaplibreMapController _mapController;
late MaplibreMapController _mapController;
List<Marker> _markers = [];
List<_MarkerState> _markerStates = [];

Expand Down Expand Up @@ -111,7 +111,8 @@ class CustomMarkerState extends State<CustomMarker> {

_mapController.toScreenLocationBatch(param).then((value) {
for (var i = 0; i < randomMarkerNum; i++) {
var point = Point<double>(value[i].x, value[i].y);
var point =
Point<double>(value[i].x as double, value[i].y as double);
_addMarker(point, param[i]);
}
});
Expand Down Expand Up @@ -147,7 +148,7 @@ class CustomMarkerState extends State<CustomMarker> {
}
Future.wait(list);
sw.stop();
results[batch][0] += sw.elapsedMilliseconds;
results[batch]![0] += sw.elapsedMilliseconds;
sw.reset();
}

Expand All @@ -162,12 +163,12 @@ class CustomMarkerState extends State<CustomMarker> {
}
Future.wait([_mapController.toScreenLocationBatch(param)]);
sw.stop();
results[batch][1] += sw.elapsedMilliseconds;
results[batch]![1] += sw.elapsedMilliseconds;
sw.reset();
}

print(
'batch=$batch,primitive=${results[batch][0] / trial}ms, batch=${results[batch][1] / trial}ms');
'batch=$batch,primitive=${results[batch]![0] / trial}ms, batch=${results[batch]![1] / trial}ms');
}
}
}
Expand All @@ -194,8 +195,8 @@ class _MarkerState extends State with TickerProviderStateMixin {

Point _position;

AnimationController _controller;
Animation<double> _animation;
late AnimationController _controller;
late Animation<double> _animation;

_MarkerState(this._position);

Expand Down
2 changes: 1 addition & 1 deletion example/lib/full_map.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FullMap extends StatefulWidget {
}

class FullMapState extends State<FullMap> {
MaplibreMapController mapController;
MaplibreMapController? mapController;

void _onMapCreated(MaplibreMapController controller) {
mapController = controller;
Expand Down
2 changes: 2 additions & 0 deletions example/lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@

// ignore_for_file: lines_longer_than_80_chars

import 'package:location_web/location_web.dart';
import 'package:maplibre_gl_web/mapbox_gl_web.dart';

import 'package:flutter_web_plugins/flutter_web_plugins.dart';

// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
LocationWebPlugin.registerWith(registrar);
MapboxMapPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
22 changes: 11 additions & 11 deletions example/lib/line.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class LineBodyState extends State<LineBody> {

static final LatLng center = const LatLng(-33.86711, 151.1947171);

MaplibreMapController controller;
MaplibreMapController? controller;
int _lineCount = 0;
Line _selectedLine;
Line? _selectedLine;

void _onMapCreated(MaplibreMapController controller) {
this.controller = controller;
Expand All @@ -41,7 +41,7 @@ class LineBodyState extends State<LineBody> {

@override
void dispose() {
controller?.onLineTapped?.remove(_onLineTapped);
controller?.onLineTapped.remove(_onLineTapped);
super.dispose();
}

Expand All @@ -64,11 +64,11 @@ class LineBodyState extends State<LineBody> {
}

void _updateSelectedLine(LineOptions changes) {
controller.updateLine(_selectedLine, changes);
controller!.updateLine(_selectedLine!, changes);
}

void _add() {
controller.addLine(
controller!.addLine(
LineOptions(
geometry: [
LatLng(-33.86711, 151.1947171),
Expand All @@ -87,15 +87,15 @@ class LineBodyState extends State<LineBody> {
}

void _remove() {
controller.removeLine(_selectedLine);
controller!.removeLine(_selectedLine!);
setState(() {
_selectedLine = null;
_lineCount -= 1;
});
}

Future<void> _changeAlpha() async {
double current = _selectedLine.options.lineOpacity;
double? current = _selectedLine!.options.lineOpacity;
if (current == null) {
// default value
current = 1.0;
Expand All @@ -107,7 +107,7 @@ class LineBodyState extends State<LineBody> {
}

Future<void> _toggleVisible() async {
double current = _selectedLine.options.lineOpacity;
double? current = _selectedLine!.options.lineOpacity;
if (current == null) {
// default value
current = 1.0;
Expand All @@ -118,7 +118,7 @@ class LineBodyState extends State<LineBody> {
}

void onStyleLoadedCallback() {
controller.addLine(
controller!.addLine(
LineOptions(
geometry: [LatLng(37.4220, -122.0841), LatLng(37.4240, -122.0941)],
lineColor: "#ff0000",
Expand Down Expand Up @@ -184,8 +184,8 @@ class LineBodyState extends State<LineBody> {
onPressed: (_selectedLine == null)
? null
: () async {
var latLngs = await controller
.getLineLatLngs(_selectedLine);
var latLngs = await controller!
.getLineLatLngs(_selectedLine!);
for (var latLng in latLngs) {
print(latLng.toString());
}
Expand Down
4 changes: 2 additions & 2 deletions example/lib/local_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class LocalStyle extends StatefulWidget {
}

class LocalStyleState extends State<LocalStyle> {
MaplibreMapController mapController;
String styleAbsoluteFilePath;
MaplibreMapController? mapController;
String? styleAbsoluteFilePath;

@override
initState() {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class MapsDemo extends StatelessWidget {
if (!kIsWeb) {
final location = Location();
final hasPermissions = await location.hasPermission();
if (hasPermissions != PermissionStatus.GRANTED) {
if (hasPermissions != PermissionStatus.granted) {
await location.requestPermission();
}
}
Expand Down
Loading

0 comments on commit 2a37ff7

Please sign in to comment.