Skip to content

Commit 4cec230

Browse files
[google_maps_flutter] Replace deprecated methods (#10377)
- Replaces `Color` methods that were deprecated in Flutter with their recommended replacement. - Replaces `cloudMapId` with the newer `mapId` from the platform interface configuration object (the former is now just a deprecated passthrough to the latter). Part of flutter/flutter#159739 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent dfa6086 commit 4cec230

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

packages/google_maps_flutter/google_maps_flutter_web/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.14+3
2+
3+
* Replaces uses of deprecated `Color` properties.
4+
15
## 0.5.14+2
26

37
* Fixes a bug where using `cloudMapId` for cloud-based styling would fail if the `style` property was also present.

packages/google_maps_flutter/google_maps_flutter_web/example/integration_test/google_maps_controller_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ void main() {
491491
mapConfiguration: const MapConfiguration(
492492
mapType: MapType.satellite,
493493
zoomControlsEnabled: true,
494-
cloudMapId: _kCloudMapId,
494+
mapId: _kCloudMapId,
495495
fortyFiveDegreeImageryEnabled: false,
496496
),
497497
);

packages/google_maps_flutter/google_maps_flutter_web/lib/src/convert.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,20 @@ final Map<int, String> _bitmapBlobUrlCache = <int, String>{};
2626

2727
// Converts a [Color] into a valid CSS value #RRGGBB.
2828
String _getCssColor(Color color) {
29-
return '#${color.value.toRadixString(16).padLeft(8, '0').substring(2)}';
29+
return '#${color.toARGB32().toRadixString(16).padLeft(8, '0').substring(2)}';
3030
}
3131

3232
// Extracts the opacity from a [Color].
3333
double _getCssOpacity(Color color) {
34-
return color.opacity;
34+
return color.a;
3535
}
3636

3737
// Converts a [Color] into a valid CSS value rgba(R, G, B, A).
3838
String _getCssColorWithAlpha(Color color) {
39-
return 'rgba(${color.red}, ${color.green}, ${color.blue}, ${(color.alpha / 255).toStringAsFixed(2)})';
39+
return 'rgba(${(color.r * 255.0).round().clamp(0, 255)}, '
40+
'${(color.g * 255.0).round().clamp(0, 255)}, '
41+
'${(color.b * 255.0).round().clamp(0, 255)}, '
42+
'${color.a.toStringAsFixed(2)})';
4043
}
4144

4245
// Converts options from the plugin into gmaps.MapOptions that can be used by the JS SDK.
@@ -122,11 +125,11 @@ gmaps.MapOptions _configurationAndStyleToGmapsOptions(
122125
options.streetViewControl = false;
123126

124127
// If using cloud map, do not set options.styles
125-
if (configuration.cloudMapId == null) {
128+
if (configuration.mapId == null) {
126129
options.styles = styles;
127130
}
128131

129-
options.mapId = configuration.cloudMapId;
132+
options.mapId = configuration.mapId;
130133

131134
return options;
132135
}

packages/google_maps_flutter/google_maps_flutter_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_maps_flutter_web
22
description: Web platform implementation of google_maps_flutter
33
repository: https://github.com/flutter/packages/tree/main/packages/google_maps_flutter/google_maps_flutter_web
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
5-
version: 0.5.14+2
5+
version: 0.5.14+3
66

77
environment:
88
sdk: ^3.7.0

0 commit comments

Comments
 (0)