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

[google_maps_flutter_platform_interface] Adds size to BitmapDescriptor (1/2) #6208

Merged
merged 3 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
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
@@ -1,5 +1,8 @@
## NEXT
## 2.2.2

* Adds a `size` parameter to `BitmapDescriptor.fromBytes`, so **web** applications
can specify the actual *physical size* of the bitmap. The parameter is not needed
(and ignored) in other platforms. Issue [#73789](https://github.com/flutter/flutter/issues/73789).
* Fixes avoid_redundant_argument_values lint warnings and minor typos.

## 2.2.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,22 @@ class BitmapDescriptor {

/// Creates a BitmapDescriptor using an array of bytes that must be encoded
/// as PNG.
static BitmapDescriptor fromBytes(Uint8List byteData) {
return BitmapDescriptor._(<Object>[_fromBytes, byteData]);
/// On the web, the [size] parameter represents the *physical size* of the
/// bitmap, regardless of the actual resolution of the encoded PNG.
/// This helps the browser to render High-DPI images at the correct size.
/// `size` is not required (and ignored, if passed) in other platforms.
static BitmapDescriptor fromBytes(Uint8List byteData, {Size? size}) {
assert(byteData.isNotEmpty,
'Cannot create BitmapDescriptor with empty byteData');
return BitmapDescriptor._(<Object>[
_fromBytes,
byteData,
if (kIsWeb && size != null)
<Object>[
size.width,
size.height,
]
]);
}

final Object _json;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/google_maps_fl
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+maps%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 2.2.1
version: 2.2.2

environment:
sdk: '>=2.12.0 <3.0.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// ignore:unnecessary_import
import 'dart:typed_data';
import 'dart:ui';

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:google_maps_flutter_platform_interface/google_maps_flutter_platform_interface.dart';
Expand All @@ -26,6 +29,56 @@ void main() {
expect(identical(descriptorFromJson.toJson(), json), isTrue); // Same JSON
});

group('fromBytes constructor', () {
test('with empty byte array, throws assertion error', () {
expect(() {
BitmapDescriptor.fromBytes(Uint8List.fromList(<int>[]));
}, throwsAssertionError);
});

test('with bytes', () {
final BitmapDescriptor descriptor = BitmapDescriptor.fromBytes(
Uint8List.fromList(<int>[1, 2, 3]),
);
expect(descriptor, isA<BitmapDescriptor>());
expect(
descriptor.toJson(),
equals(<Object>[
'fromBytes',
<int>[1, 2, 3],
]));
});

test('with size, not on the web, size is ignored', () {
final BitmapDescriptor descriptor = BitmapDescriptor.fromBytes(
Uint8List.fromList(<int>[1, 2, 3]),
size: const Size(40, 20),
);

expect(
descriptor.toJson(),
equals(<Object>[
'fromBytes',
<int>[1, 2, 3],
]));
}, skip: kIsWeb);

test('with size, on the web, size is preserved', () {
final BitmapDescriptor descriptor = BitmapDescriptor.fromBytes(
Uint8List.fromList(<int>[1, 2, 3]),
size: const Size(40, 20),
);

expect(
descriptor.toJson(),
equals(<Object>[
'fromBytes',
<int>[1, 2, 3],
<int>[40, 20],
]));
}, skip: !kIsWeb);
});

group('fromJson validation', () {
group('type validation', () {
test('correct type', () {
Expand Down