Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Uncomment Marker icons now that ImageListener API change has landed in stable #2443

Merged
merged 5 commits into from
Sep 16, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import 'dart:async';
import 'dart:math';
import 'dart:ui';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
Expand Down Expand Up @@ -245,42 +246,36 @@ class PlaceMarkerBodyState extends State<PlaceMarkerBody> {
});
}

// A breaking change to the ImageStreamListener API affects this sample.
// I've updates the sample to use the new API, but as we cannot use the new
// API before it makes it to stable I'm commenting out this sample for now
// TODO(amirh): uncomment this one the ImageStream API change makes it to stable.
// https://github.com/flutter/flutter/issues/33438
//
// void _setMarkerIcon(BitmapDescriptor assetIcon) {
// if (selectedMarker == null) {
// return;
// }
//
// final Marker marker = markers[selectedMarker];
// setState(() {
// markers[selectedMarker] = marker.copyWith(
// iconParam: assetIcon,
// );
// });
// }
//
// Future<BitmapDescriptor> _getAssetIcon(BuildContext context) async {
// final Completer<BitmapDescriptor> bitmapIcon =
// Completer<BitmapDescriptor>();
// final ImageConfiguration config = createLocalImageConfiguration(context);
//
// const AssetImage('assets/red_square.png')
// .resolve(config)
// .addListener(ImageStreamListener((ImageInfo image, bool sync) async {
// final ByteData bytes =
// await image.image.toByteData(format: ImageByteFormat.png);
// final BitmapDescriptor bitmap =
// BitmapDescriptor.fromBytes(bytes.buffer.asUint8List());
// bitmapIcon.complete(bitmap);
// }));
//
// return await bitmapIcon.future;
// }
void _setMarkerIcon(MarkerId markerId, BitmapDescriptor assetIcon) {
final Marker marker = markers[markerId]!;
setState(() {
markers[markerId] = marker.copyWith(
iconParam: assetIcon,
);
});
}

Future<BitmapDescriptor> _getAssetIcon(BuildContext context) async {
final Completer<BitmapDescriptor> bitmapIcon =
Completer<BitmapDescriptor>();
final ImageConfiguration config = createLocalImageConfiguration(context);

const AssetImage('assets/red_square.png')
.resolve(config)
.addListener(ImageStreamListener((ImageInfo image, bool sync) async {
final ByteData? bytes =
await image.image.toByteData(format: ImageByteFormat.png);
if (bytes == null) {
bitmapIcon.completeError(Exception('Unable to encode icon'));
return;
}
final BitmapDescriptor bitmap =
BitmapDescriptor.fromBytes(bytes.buffer.asUint8List());
bitmapIcon.complete(bitmap);
}));

return await bitmapIcon.future;
}

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -386,22 +381,18 @@ class PlaceMarkerBodyState extends State<PlaceMarkerBody> {
? null
: () => _changeZIndex(selectedId),
),
// A breaking change to the ImageStreamListener API affects this sample.
// I've updates the sample to use the new API, but as we cannot use the new
// API before it makes it to stable I'm commenting out this sample for now
// TODO(amirh): uncomment this one the ImageStream API change makes it to stable.
// https://github.com/flutter/flutter/issues/33438
//
// TextButton(
// child: const Text('set marker icon'),
// onPressed: () {
// _getAssetIcon(context).then(
// (BitmapDescriptor icon) {
// _setMarkerIcon(icon);
// },
// );
// },
// ),
TextButton(
child: const Text('set marker icon'),
onPressed: selectedId == null
? null
: () {
_getAssetIcon(context).then(
(BitmapDescriptor icon) {
_setMarkerIcon(selectedId, icon);
},
);
},
),
],
),
],
Expand Down