Skip to content

Commit cedf32b

Browse files
authored
[google_maps_flutter_platform_interface] Add map background color configuration (#13014)
First landing PR for the background-color feature reviewed in #12357. This PR contains only the `google_maps_flutter_platform_interface` changes, as requested in [the combined PR discussion](#12357 (comment)). Adds nullable `MapConfiguration.backgroundColor`, includes it in configuration diffing, equality, hashing, and legacy serialization, and adds tests for those contracts. Bumps the package to 2.18.0 and folds the existing `NEXT` minimum-SDK entry into that release. The implementation and app-facing changes remain in #12357 and will be split into follow-up PRs after this package lands and is published. This is part of flutter/flutter#142520; the issue should remain open until the full feature lands. Validation: repository formatter, analysis, Dart tests, validation, publish dry-run (zero warnings), and license check all pass. ## Pre-Review Checklist
1 parent 54706bd commit cedf32b

6 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎packages/google_maps_flutter/google_maps_flutter_platform_interface/CHANGELOG.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.18.0
22

3+
* Adds support for configuring the color displayed behind unloaded map tiles.
34
* Updates minimum supported SDK version to Flutter 3.41/Dart 3.11.
45

56
## 2.17.0

‎packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/map_configuration.dart‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class MapConfiguration {
4343
String? mapId,
4444
@Deprecated('cloudMapId is deprecated. Use mapId instead.') String? cloudMapId,
4545
this.style,
46+
this.backgroundColor,
4647
this.markerType,
4748
this.colorScheme,
4849
}) : mapId = mapId ?? cloudMapId;
@@ -154,6 +155,12 @@ class MapConfiguration {
154155
/// To clear a previously set style, set this to an empty string.
155156
final String? style;
156157

158+
/// The color displayed behind the map while map tiles load.
159+
///
160+
/// This option may only take effect when the map is initialized, depending
161+
/// on the platform implementation.
162+
final Color? backgroundColor;
163+
157164
/// The type of marker that the map should use.
158165
///
159166
/// Advanced and legacy markers could be handled differently by platform
@@ -239,6 +246,7 @@ class MapConfiguration {
239246
: null,
240247
mapId: mapId != other.mapId ? mapId : null,
241248
style: style != other.style ? style : null,
249+
backgroundColor: backgroundColor != other.backgroundColor ? backgroundColor : null,
242250
markerType: markerType != other.markerType ? markerType : null,
243251
colorScheme: colorScheme != other.colorScheme ? colorScheme : null,
244252
);
@@ -276,6 +284,7 @@ class MapConfiguration {
276284
streetViewControlEnabled: diff.streetViewControlEnabled ?? streetViewControlEnabled,
277285
mapId: diff.mapId ?? mapId,
278286
style: diff.style ?? style,
287+
backgroundColor: diff.backgroundColor ?? backgroundColor,
279288
markerType: diff.markerType ?? markerType,
280289
colorScheme: diff.colorScheme ?? colorScheme,
281290
);
@@ -310,6 +319,7 @@ class MapConfiguration {
310319
streetViewControlEnabled == null &&
311320
mapId == null &&
312321
style == null &&
322+
backgroundColor == null &&
313323
markerType == null &&
314324
colorScheme == null;
315325

@@ -349,6 +359,7 @@ class MapConfiguration {
349359
streetViewControlEnabled == other.streetViewControlEnabled &&
350360
mapId == other.mapId &&
351361
style == other.style &&
362+
backgroundColor == other.backgroundColor &&
352363
markerType == other.markerType &&
353364
colorScheme == other.colorScheme;
354365
}
@@ -382,6 +393,7 @@ class MapConfiguration {
382393
streetViewControlEnabled,
383394
mapId,
384395
style,
396+
backgroundColor,
385397
markerType,
386398
colorScheme,
387399
]);

‎packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/utils/map_configuration_serialization.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Map<String, Object> jsonForMapConfiguration(MapConfiguration config) {
4747
if (config.cloudMapId != null) 'cloudMapId': config.cloudMapId!,
4848
if (config.mapId != null) 'mapId': config.mapId!,
4949
if (config.style != null) 'style': config.style!,
50+
if (config.backgroundColor != null) 'backgroundColor': config.backgroundColor!.toARGB32(),
5051
if (config.markerType != null) 'markerType': config.markerType!.index,
5152
};
5253
}

‎packages/google_maps_flutter/google_maps_flutter_platform_interface/pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/google_maps_f
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 2.17.0
7+
version: 2.18.0
88

99
environment:
1010
sdk: ^3.11.0

‎packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/map_configuration_test.dart‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void main() {
4040
fullscreenControlEnabled: false,
4141
streetViewControlEnabled: false,
4242
style: 'diff base style',
43+
backgroundColor: Colors.black,
4344
);
4445

4546
test('only include changed fields', () async {
@@ -478,6 +479,22 @@ void main() {
478479
expect(empty.hashCode, isNot(diff.hashCode));
479480
});
480481

482+
test('handle backgroundColor', () async {
483+
const diff = MapConfiguration(backgroundColor: Colors.white);
484+
485+
const empty = MapConfiguration();
486+
final MapConfiguration updated = diffBase.applyDiff(diff);
487+
488+
// A diff applied to empty options should be the diff itself.
489+
expect(empty.applyDiff(diff), diff);
490+
// The diff from empty options should be the diff itself.
491+
expect(diff.diffFrom(empty), diff);
492+
// A diff applied to non-empty options should update that field.
493+
expect(updated.backgroundColor, Colors.white);
494+
// The hash code should change.
495+
expect(empty.hashCode, isNot(diff.hashCode));
496+
});
497+
481498
test('handle colorScheme', () async {
482499
const diff = MapConfiguration(colorScheme: MapColorScheme.followSystem);
483500

@@ -683,6 +700,12 @@ void main() {
683700
expect(diff.isEmpty, false);
684701
});
685702

703+
test('is false with backgroundColor', () async {
704+
const diff = MapConfiguration(backgroundColor: Colors.white);
705+
706+
expect(diff.isEmpty, false);
707+
});
708+
686709
test('is false with colorScheme', () async {
687710
const diff = MapConfiguration(colorScheme: MapColorScheme.followSystem);
688711

‎packages/google_maps_flutter/google_maps_flutter_platform_interface/test/utils/map_configuration_serialization_test.dart‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ void main() {
4242
buildingsEnabled: false,
4343
mapId: _kMapId,
4444
cloudMapId: _kMapId,
45+
backgroundColor: const Color(0xFF123456),
4546
);
4647

4748
final Map<String, Object> json = jsonForMapConfiguration(config);
@@ -77,6 +78,7 @@ void main() {
7778
'buildingsEnabled': false,
7879
'mapId': _kMapId,
7980
'cloudMapId': _kMapId,
81+
'backgroundColor': 0xFF123456,
8082
});
8183
});
8284

0 commit comments

Comments
 (0)