Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.0.0] - (April 09, 2021)

* Added null safety

## [0.0.3] - (January 08, 2021)

Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 19 additions & 14 deletions example/lib/stateful_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,26 @@ class StatefulExample extends StatefulWidget {
}

class _StatefulExampleState extends State<StatefulExample> {
List<MarkerItem> markers = List();
List<MarkerItem> 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) {
Expand Down
52 changes: 26 additions & 26 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"
51 changes: 33 additions & 18 deletions lib/interactive_maps_marker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ 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 {
final LatLng center;
final double itemHeight;
final double zoom;
@required
List<MarkerItem> items;
final List<MarkerItem> items;
@required
final IndexedWidgetBuilder itemContent;

Expand All @@ -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<InteractiveMapsMarker> {
Completer<GoogleMapController> _controller = Completer();
GoogleMapController mapController;
late GoogleMapController mapController;
PageController pageController = PageController(viewportFraction: 0.9);

Set<Marker> markers;
Uint8List? markerIcon;
Uint8List? markerIconSelected;

late Set<Marker> markers;
int currentIndex = 0;
ValueNotifier selectedMarker = ValueNotifier<int>(null);
ValueNotifier selectedMarker = ValueNotifier<int?>(null);

@override
void initState() {
Expand Down Expand Up @@ -107,10 +107,21 @@ class _InteractiveMapsMarkerState extends State<InteractiveMapsMarker> {
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,
Expand Down Expand Up @@ -164,10 +175,12 @@ class _InteractiveMapsMarkerState extends State<InteractiveMapsMarker> {
}

Future<void> 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<Marker> _markers = Set<Marker>();

Expand All @@ -185,7 +198,9 @@ class _InteractiveMapsMarkerState extends State<InteractiveMapsMarker> {
);
_pageChanged(tappedIndex);
},
icon: item.id == current ? BitmapDescriptor.fromBytes(widget.markerIconSelected) : BitmapDescriptor.fromBytes(widget.markerIcon),
icon: item.id == current
? BitmapDescriptor.fromBytes(markerIconSelected!)
: BitmapDescriptor.fromBytes(markerIcon!),
),
);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ Future<Uint8List> 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();
}
Loading