From c10dae4abc39707883b4109b673654b11672fbe8 Mon Sep 17 00:00:00 2001 From: BackTracker43 Date: Fri, 9 Apr 2021 17:02:33 +0500 Subject: [PATCH] Migrate to null safety --- CHANGELOG.md | 3 ++ README.md | 9 +++++- example/lib/stateful_example.dart | 33 +++++++++++--------- example/pubspec.lock | 52 +++++++++++++++---------------- lib/interactive_maps_marker.dart | 51 +++++++++++++++++++----------- lib/utils.dart | 2 +- pubspec.lock | 50 ++++++++++++++--------------- pubspec.yaml | 6 ++-- 8 files changed, 118 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32596d2..e9ad834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [1.0.0] - (April 09, 2021) + +* Added null safety ## [0.0.3] - (January 08, 2021) diff --git a/README.md b/README.md index faf350d..3a70e1b 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,15 @@ Easy to use Animated Maps Markers with detail card. Use it for store or any plac Add this package to your `pubspec.yaml` in `dependencies:` section ```yaml dependencies: - interactive_maps_marker: ^0.0.2 + interactive_maps_marker: ^1.0.0 ``` + +Not migrated to null safety yet? use old version like this +```yaml +dependencies: + interactive_maps_marker: ^0.0.3 +``` + This package depends upon ```google_maps_flutter``` so first setup this by following [This Guide](https://pub.dev/packages/google_maps_flutter) Update dependencies diff --git a/example/lib/stateful_example.dart b/example/lib/stateful_example.dart index 3b4944b..9ec6fbf 100644 --- a/example/lib/stateful_example.dart +++ b/example/lib/stateful_example.dart @@ -9,21 +9,26 @@ class StatefulExample extends StatefulWidget { } class _StatefulExampleState extends State { - List markers = List(); + List markers = [ + MarkerItem(id: 1, latitude: 31.4673274, longitude: 74.2637687), + MarkerItem(id: 2, latitude: 31.4718461, longitude: 74.3531591), + MarkerItem(id: 3, latitude: 31.5325107, longitude: 74.3610325), + MarkerItem(id: 4, latitude: 31.4668809, longitude: 74.3135454), + ]; - @override - void initState() { - super.initState(); -// Fake delay for simulating a network request - Future.delayed(Duration(seconds: 2)).then((value) { - setState(() { - markers.add(MarkerItem(id: 1, latitude: 31.4673274, longitude: 74.2637687)); - markers.add(MarkerItem(id: 2, latitude: 31.4718461, longitude: 74.3531591)); - markers.add(MarkerItem(id: 3, latitude: 31.5325107, longitude: 74.3610325)); - markers.add(MarkerItem(id: 4, latitude: 31.4668809, longitude: 74.31354)); - }); - }); - } +// @override +// void initState() { +// super.initState(); +// // Fake delay for simulating a network request +// Future.delayed(Duration(seconds: 0)).then((value) { +// setState(() { +// markers.add(MarkerItem(id: 1, latitude: 31.4673274, longitude: 74.2637687)); +// markers.add(MarkerItem(id: 2, latitude: 31.4718461, longitude: 74.3531591)); +// markers.add(MarkerItem(id: 3, latitude: 31.5325107, longitude: 74.3610325)); +// markers.add(MarkerItem(id: 4, latitude: 31.4668809, longitude: 74.3135402)); +// }); +// }); +// } @override Widget build(BuildContext context) { diff --git a/example/pubspec.lock b/example/pubspec.lock index afe8cc4..ca0c7b8 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -7,42 +7,42 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" cupertino_icons: dependency: "direct main" description: @@ -56,7 +56,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -68,7 +68,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "2.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -80,49 +80,49 @@ packages: name: google_maps_flutter url: "https://pub.dartlang.org" source: hosted - version: "1.0.6" + version: "2.0.3" google_maps_flutter_platform_interface: dependency: transitive description: name: google_maps_flutter_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.4" interactive_maps_marker: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.0.2" + version: "1.0.0" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -134,63 +134,63 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" stream_transform: dependency: transitive description: name: stream_transform url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.22.0 <2.0.0" + dart: ">=2.12.2 <3.0.0" + flutter: ">=1.22.0" diff --git a/lib/interactive_maps_marker.dart b/lib/interactive_maps_marker.dart index 9345ec8..b1f2305 100644 --- a/lib/interactive_maps_marker.dart +++ b/lib/interactive_maps_marker.dart @@ -14,7 +14,7 @@ class MarkerItem { double latitude; double longitude; - MarkerItem({this.id, this.latitude, this.longitude}); + MarkerItem({required this.id, required this.latitude, required this.longitude}); } class InteractiveMapsMarker extends StatefulWidget { @@ -22,7 +22,7 @@ class InteractiveMapsMarker extends StatefulWidget { final double itemHeight; final double zoom; @required - List items; + final List items; @required final IndexedWidgetBuilder itemContent; @@ -31,31 +31,31 @@ class InteractiveMapsMarker extends StatefulWidget { final Alignment contentAlignment; InteractiveMapsMarker({ - this.items, - this.itemBuilder, + required this.items, + required this.itemBuilder, this.center = const LatLng(0.0, 0.0), - this.itemContent, + required this.itemContent, this.itemHeight = 116, this.zoom = 12.0, this.itemPadding = const EdgeInsets.only(bottom: 80.0), this.contentAlignment = Alignment.bottomCenter, }); - Uint8List markerIcon; - Uint8List markerIconSelected; - @override _InteractiveMapsMarkerState createState() => _InteractiveMapsMarkerState(); } class _InteractiveMapsMarkerState extends State { Completer _controller = Completer(); - GoogleMapController mapController; + late GoogleMapController mapController; PageController pageController = PageController(viewportFraction: 0.9); - Set markers; + Uint8List? markerIcon; + Uint8List? markerIconSelected; + + late Set markers; int currentIndex = 0; - ValueNotifier selectedMarker = ValueNotifier(null); + ValueNotifier selectedMarker = ValueNotifier(null); @override void initState() { @@ -107,10 +107,21 @@ class _InteractiveMapsMarkerState extends State { return Positioned.fill( child: ValueListenableBuilder( valueListenable: selectedMarker, - builder: (context, value, child) { - return GoogleMap( + builder: (context, dynamic value, child) { + return value == null + ? GoogleMap( + zoomControlsEnabled: false, + myLocationEnabled: true, + myLocationButtonEnabled: false, + onMapCreated: _onMapCreated, + initialCameraPosition: CameraPosition( + target: widget.center, + zoom: widget.zoom, + ), + ) + : GoogleMap( zoomControlsEnabled: false, - markers: value == null ? null : markers, + markers: markers, myLocationEnabled: true, myLocationButtonEnabled: false, onMapCreated: _onMapCreated, @@ -164,10 +175,12 @@ class _InteractiveMapsMarkerState extends State { } Future rebuildMarkers(int index) async { - int current = widget.items[index].id; + int current = widget.items[currentIndex].id; - if (widget.markerIcon == null) widget.markerIcon = await getBytesFromAsset('packages/interactive_maps_marker/assets/marker.png', 100); - if (widget.markerIconSelected == null) widget.markerIconSelected = await getBytesFromAsset('packages/interactive_maps_marker/assets/marker_selected.png', 100); + if (markerIcon == null) + markerIcon = await getBytesFromAsset('packages/interactive_maps_marker/assets/marker.png', 100); + if (markerIconSelected == null) + markerIconSelected = await getBytesFromAsset('packages/interactive_maps_marker/assets/marker_selected.png', 100); Set _markers = Set(); @@ -185,7 +198,9 @@ class _InteractiveMapsMarkerState extends State { ); _pageChanged(tappedIndex); }, - icon: item.id == current ? BitmapDescriptor.fromBytes(widget.markerIconSelected) : BitmapDescriptor.fromBytes(widget.markerIcon), + icon: item.id == current + ? BitmapDescriptor.fromBytes(markerIconSelected!) + : BitmapDescriptor.fromBytes(markerIcon!), ), ); }); diff --git a/lib/utils.dart b/lib/utils.dart index c2cc1cb..7601763 100644 --- a/lib/utils.dart +++ b/lib/utils.dart @@ -7,5 +7,5 @@ Future getBytesFromAsset(String path, int width) async { ByteData data = await rootBundle.load(path); ui.Codec codec = await ui.instantiateImageCodec(data.buffer.asUint8List(), targetWidth: width); ui.FrameInfo fi = await codec.getNextFrame(); - return (await fi.image.toByteData(format: ui.ImageByteFormat.png)).buffer.asUint8List(); + return (await fi.image.toByteData(format: ui.ImageByteFormat.png))!.buffer.asUint8List(); } diff --git a/pubspec.lock b/pubspec.lock index 7ec5fbe..bc48cd3 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.1" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.3" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -61,7 +61,7 @@ packages: name: flutter_plugin_android_lifecycle url: "https://pub.dartlang.org" source: hosted - version: "1.0.8" + version: "2.0.1" flutter_test: dependency: "direct dev" description: flutter @@ -73,42 +73,42 @@ packages: name: google_maps_flutter url: "https://pub.dartlang.org" source: hosted - version: "1.0.6" + version: "2.0.3" google_maps_flutter_platform_interface: dependency: transitive description: name: google_maps_flutter_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "2.0.4" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.1" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.1" + version: "1.8.0" plugin_platform_interface: dependency: transitive description: name: plugin_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "1.0.2" + version: "2.0.0" sky_engine: dependency: transitive description: flutter @@ -120,63 +120,63 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.2" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.1" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.1" + version: "2.1.0" stream_transform: dependency: transitive description: name: stream_transform url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "2.0.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.1" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.2" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.3" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" sdks: - dart: ">=2.10.0-110 <2.11.0" - flutter: ">=1.22.0 <2.0.0" + dart: ">=2.12.2 <3.0.0" + flutter: ">=1.22.0" diff --git a/pubspec.yaml b/pubspec.yaml index cbf6ec1..0cef938 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,16 +1,16 @@ name: interactive_maps_marker description: Easy to use Animated Maps Markers with detail card. Use it for store or any place locator. -version: 0.0.3 +version: 1.0.0 maintainer: Atiq Samtia (@AtiqSamtia) homepage: https://github.com/atiqsamtia/interactive_maps_marker_flutter environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.12.2 <3.0.0" dependencies: flutter: sdk: flutter - google_maps_flutter: ^1.0.6 + google_maps_flutter: ^2.0.3 dev_dependencies: flutter_test: