Skip to content

[google_maps_flutter_android] Default useAndroidViewSurface to true for Hybrid Composition - #13717

Draft
ahmedalam782 wants to merge 3 commits into
flutter:mainfrom
ahmedalam782:fix/google-maps-android-hybrid-composition-default
Draft

ahmedalam782 wants to merge 3 commits into
flutter:mainfrom
ahmedalam782:fix/google-maps-android-hybrid-composition-default

Conversation

@ahmedalam782

Copy link
Copy Markdown

Description

Switches the default value of useAndroidViewSurface in google_maps_flutter_android from false to true so Android uses Hybrid Composition (PlatformViewLink + AndroidViewSurface) by default instead of Texture Layer Hybrid Composition (TextureView).

On some Android devices (notably Huawei EMUI devices such as Huawei Nova 5T), TLHC TextureView renders a blank beige surface instead of the map unless Hybrid Composition is enabled.

Changes

  • Set useAndroidViewSurface = true by default in GoogleMapsFlutterAndroid.
  • Updated README.md Display Mode documentation.
  • Updated unit tests in test/google_maps_flutter_android_test.dart.
  • Bumped google_maps_flutter_android to 2.21.2 and updated CHANGELOG.md and pubspec.yaml.

@google-cla

google-cla Bot commented Nov 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions
github-actions Bot marked this pull request as draft November 19, 2026 07:05
@github-actions github-actions Bot added the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 19, 2026
@github-actions

Copy link
Copy Markdown

This pull request has been moved to a draft state because the cla/google check failed. Once you have signed the CLA and the cla/google check is passing, please mark this pull request as Ready for review.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request changes the default value of useAndroidViewSurface to true in google_maps_flutter_android, switching the default platform view mode to Hybrid Composition. It updates the documentation, updates several package dependencies in pubspec.yaml, and adapts existing tests to reflect this new default. Feedback on the changes suggests adding test coverage to verify that the correct marker type is passed and that the marker type defaults to legacy when useAndroidViewSurface is set to true, as the current tests explicitly set it to false.


test('Correct marker type is passed to platform view', () async {
final maps = GoogleMapsFlutterAndroid();
maps.useAndroidViewSurface = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since useAndroidViewSurface now defaults to true, explicitly setting it to false in this test means there is no test coverage verifying that the correct marker type is passed when using the new default PlatformViewLink implementation. Consider adding a corresponding test case to verify this behavior when useAndroidViewSurface is true.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@google-cla I signed it!


test('marker type defaults to legacy if unset', () async {
final maps = GoogleMapsFlutterAndroid();
maps.useAndroidViewSurface = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since useAndroidViewSurface now defaults to true, explicitly setting it to false in this test means there is no test coverage verifying that the marker type defaults to legacy when using the new default PlatformViewLink implementation. Consider adding a corresponding test case to verify this behavior when useAndroidViewSurface is true.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@google-cla I signed it!

@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 19, 2026
@ahmedalam782

Copy link
Copy Markdown
Author

@google-cla I signed it!

@ahmedalam782
ahmedalam782 marked this pull request as ready for review November 19, 2026 12:33
@github-actions
github-actions Bot marked this pull request as draft November 19, 2026 12:33
@github-actions github-actions Bot added the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 19, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request switches the default value of useAndroidViewSurface to true in google_maps_flutter_android, making Hybrid Composition the default display mode. It updates the README, CHANGELOG, and dependencies in pubspec.yaml. Additionally, the tests are updated to reflect this default change, and new tests are added to verify the behavior under PlatformViewLink. A review comment suggests using tester.binding.defaultBinaryMessenger for idiomatic widget testing and adding safer type checking for the platform view creation parameters to prevent potential test crashes.

Comment on lines +1440 to +1464
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform_views,
(MethodCall methodCall) async {
if (methodCall.method == 'create') {
final args = Map<String, dynamic>.from(methodCall.arguments as Map<dynamic, dynamic>);
if (args.containsKey('params')) {
final paramsUint8List = args['params'] as Uint8List;
final byteData = ByteData.sublistView(paramsUint8List);
final creationParams =
MapsApi.pigeonChannelCodec.decodeMessage(byteData)
as PlatformMapViewCreationParams?;
if (creationParams != null && !completer.isCompleted) {
completer.complete(creationParams);
}
}
}
return 0;
},
);
addTearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform_views,
null,
);
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using tester.binding.defaultBinaryMessenger is more idiomatic in widget tests than accessing TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger directly.

Additionally, casting args['params'] directly to Uint8List using as Uint8List can throw a TypeError if the parameters are null or of a different type. It is safer to use type checking (is Uint8List) to prevent potential test crashes.

    tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
      SystemChannels.platform_views,
      (MethodCall methodCall) async {
        if (methodCall.method == 'create') {
          final Map<String, dynamic> args = Map<String, dynamic>.from(methodCall.arguments as Map<dynamic, dynamic>);
          final Object? params = args['params'];
          if (params is Uint8List) {
            final ByteData byteData = ByteData.sublistView(params);
            final PlatformMapViewCreationParams? creationParams = 
                MapsApi.pigeonChannelCodec.decodeMessage(byteData)
                    as PlatformMapViewCreationParams?;
            if (creationParams != null && !completer.isCompleted) {
              completer.complete(creationParams);
            }
          }
        }
        return 0;
      },
    );
    addTearDown(() {
      tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
        SystemChannels.platform_views,
        null,
      );
    });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting for response The Flutter team cannot make further progress on this PR until the author responds

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant