Skip to content

Commit

Permalink
Update and comment out the 'set marker icon' sample.
Browse files Browse the repository at this point in the history
This updates the sample to adapt to the ImageStream listener API changes
in flutter/flutter#32936

As we cannot use the new API before it makes it to stable I'm commenting
out the sample for now(if we update it now it won't compile on stable,
and if we leave it as is it breaks CI on master).
  • Loading branch information
Amir Hardon committed May 28, 2019
1 parent 5269688 commit f12ca58
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 42 deletions.
5 changes: 5 additions & 0 deletions packages/google_maps_flutter/CHANGELOG.md
@@ -1,3 +1,8 @@
## 0.5.14+1

* Example app update(comment out usage of the ImageStreamListener API which has a breaking change
that's not yet on master). See: https://github.com/flutter/flutter/issues/33438

## 0.5.14

* Adds onLongPress callback for GoogleMap.
Expand Down
93 changes: 52 additions & 41 deletions packages/google_maps_flutter/example/lib/place_marker.dart
Expand Up @@ -4,7 +4,6 @@

import 'dart:async';
import 'dart:math';
import 'dart:typed_data';
import 'dart:ui';

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

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((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;
}
// 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;
// }

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -330,16 +335,22 @@ class PlaceMarkerBodyState extends State<PlaceMarkerBody> {
child: const Text('change zIndex'),
onPressed: _changeZIndex,
),
FlatButton(
child: const Text('set marker icon'),
onPressed: () {
_getAssetIcon(context).then(
(BitmapDescriptor icon) {
_setMarkerIcon(icon);
},
);
},
),
// 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
//
// FlatButton(
// child: const Text('set marker icon'),
// onPressed: () {
// _getAssetIcon(context).then(
// (BitmapDescriptor icon) {
// _setMarkerIcon(icon);
// },
// );
// },
// ),
],
),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/google_maps_flutter/pubspec.yaml
Expand Up @@ -2,7 +2,7 @@ name: google_maps_flutter
description: A Flutter plugin for integrating Google Maps in iOS and Android applications.
author: Flutter Team <flutter-dev@googlegroups.com>
homepage: https://github.com/flutter/plugins/tree/master/packages/google_maps_flutter
version: 0.5.14
version: 0.5.14+1

dependencies:
flutter:
Expand Down

0 comments on commit f12ca58

Please sign in to comment.