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

Null Safety #7

Merged
merged 8 commits into from
Jul 1, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 10 additions & 8 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@


import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:lat_lon_grid_plugin/lat_lon_grid_plugin.dart';
import 'package:latlong/latlong.dart';
import 'package:latlong2/latlong.dart';

void main() => runApp(MyApp());

Expand All @@ -22,14 +24,14 @@ class MyApp extends StatelessWidget {
/// HomePage which shows the use of the plugin
class HomePage extends StatefulWidget {
/// constructor for the HomePage widget
HomePage({Key key}) : super(key: key);
HomePage({Key? key}) : super(key: key);

@override
_HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
MapController _mapController;
MapController? _mapController;
String _sLatLonZoom = '';
double _rotation = 0.0;

Expand All @@ -38,14 +40,14 @@ class _HomePageState extends State<HomePage> {
_rotation = valRotation;
_updateLabel();
});
_mapController.rotate(valRotation);
_mapController!.rotate(valRotation);
}

void _updateLabel() {
if (_mapController != null) {
String lat = _mapController.center.latitude.toStringAsFixed(3);
String lon = _mapController.center.longitude.toStringAsFixed(3);
String zoom = _mapController.zoom.toStringAsFixed(2);
String lat = _mapController!.center.latitude.toStringAsFixed(3);
String lon = _mapController!.center.longitude.toStringAsFixed(3);
String zoom = _mapController!.zoom.toStringAsFixed(2);
String rotation = _rotation.toStringAsFixed(0);

// don't trigger rebuild while building aka. when the first build didn't finish yet
Expand All @@ -65,7 +67,7 @@ class _HomePageState extends State<HomePage> {
_mapController = MapController();
// hacked together
// https://stackoverflow.com/questions/49466556/flutter-run-method-on-widget-build-complete
WidgetsBinding.instance.addPostFrameCallback((_) => _updateLabel());
WidgetsBinding.instance!.addPostFrameCallback((_) => _updateLabel());
}

@override
Expand Down