Skip to content

Commit 8b51bc0

Browse files
committed
[google_maps_flutter_platform_interface] Documentation improvements
- Improves public api for width and height values of the MapBitmap - Also includes small fix to test naming.
1 parent b3e6acd commit 8b51bc0

File tree

2 files changed

+73
-28
lines changed

2 files changed

+73
-28
lines changed

packages/google_maps_flutter/google_maps_flutter_platform_interface/lib/src/types/bitmap.dart

Lines changed: 71 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum MapBitmapScaling {
2626
///
2727
/// This can be used if the image is already pre-scaled, or to increase
2828
/// performance with a large numbers of markers.
29-
noScaling,
29+
none,
3030
}
3131

3232
// The default pixel ratio for custom bitmaps.
@@ -316,6 +316,29 @@ class BitmapDescriptor {
316316
/// Represents a [BitmapDescriptor] base class for map bitmaps.
317317
///
318318
/// See [AssetMapBitmap] and [BytesMapBitmap] for concrete implementations.
319+
///
320+
/// The [imagePixelRatio] should be set to the correct pixel ratio of bitmap
321+
/// image. If the [width] or [height] is provided, the [imagePixelRatio]
322+
/// value is ignored.
323+
///
324+
/// [bitmapScaling] controls the scaling behavior:
325+
/// - [MapBitmapScaling.auto] automatically upscales and downscales the image
326+
/// to match the device's pixel ratio or the specified dimensions,
327+
/// maintaining consistency across devices.
328+
/// - [MapBitmapScaling.none] disables automatic scaling, which is
329+
/// useful when performance is a concern or if the asset is already scaled
330+
/// appropriately.
331+
///
332+
/// Optionally, [width] and [height] can be specified to control the dimensions
333+
/// of the rendered image:
334+
/// - If both [width] and [height] are non-null, the image will have the
335+
/// specified dimensions, which might distort the original aspect ratio,
336+
/// similar to [BoxFit.fill].
337+
/// - If only one of [width] and [height] is non-null, then the output image
338+
/// will be scaled to the associated width or height, and the other dimension
339+
/// will take whatever value is needed to maintain the image's original aspect
340+
/// ratio. These cases are similar to [BoxFit.fitWidth] and
341+
/// [BoxFit.fitHeight], respectively.
319342
abstract class MapBitmap extends BitmapDescriptor {
320343
MapBitmap._({
321344
required this.bitmapScaling,
@@ -328,12 +351,35 @@ abstract class MapBitmap extends BitmapDescriptor {
328351
final MapBitmapScaling bitmapScaling;
329352

330353
/// The pixel ratio of the bitmap.
354+
///
355+
/// If the [width] or [height] is provided, the [imagePixelRatio]
356+
/// value is ignored.
331357
final double imagePixelRatio;
332358

333359
/// The target width of the bitmap in logical pixels.
360+
///
361+
/// - If [width] is provided and [height] is null, the image will be scaled to
362+
/// the associated width, and the height will take whatever value is needed
363+
/// to maintain the image's original aspect ratio. This is similar to
364+
/// [BoxFit.fitWidth].
365+
/// - If both [width] and [height] are non-null, the image will have the
366+
/// specified dimensions, which might distort the original aspect ratio,
367+
/// similar to [BoxFit.fill].
368+
/// - If neither [width] nor [height] is provided, the image will be rendered
369+
/// using the [imagePixelRatio] value.
334370
final double? width;
335371

336372
/// The target height of the bitmap in logical pixels.
373+
///
374+
/// - If [height] is provided and [width] is null, the image will be scaled to
375+
/// the associated height, and the width will take whatever value is needed
376+
/// to maintain the image's original aspect ratio. This is similar to
377+
/// [BoxFit.fitHeight].
378+
/// - If both [width] and [height] are non-null, the image will have the
379+
/// specified dimensions, which might distort the original aspect ratio,
380+
/// similar to [BoxFit.fill].
381+
/// - If neither [width] nor [height] is provided, the image will be rendered
382+
/// using the [imagePixelRatio] value.
337383
final double? height;
338384
}
339385

@@ -375,10 +421,10 @@ abstract class MapBitmap extends BitmapDescriptor {
375421
/// - If both [width] and [height] are non-null, the image will have the
376422
/// specified dimensions, which might distort the original aspect ratio,
377423
/// similar to [BoxFit.fill].
378-
/// - If only one of `width` and `height` is non-null, then the output image
424+
/// - If only one of [width] and [height] is non-null, then the output image
379425
/// will be scaled to the associated width or height, and the other dimension
380426
/// will take whatever value is needed to maintain the image's original aspect
381-
/// ratio. These cases are simnilar to [BoxFit.fitWidth] and
427+
/// ratio. These cases are similar to [BoxFit.fitWidth] and
382428
/// [BoxFit.fitHeight], respectively.
383429
///
384430
/// ```dart
@@ -432,7 +478,7 @@ class AssetMapBitmap extends MapBitmap {
432478
/// - [MapBitmapScaling.auto] automatically upscales and downscales the image
433479
/// to match the device's pixel ratio or the specified dimensions,
434480
/// maintaining consistency across devices.
435-
/// - [MapBitmapScaling.noScaling] disables automatic scaling, which is
481+
/// - [MapBitmapScaling.none] disables automatic scaling, which is
436482
/// useful when performance is a concern or if the asset is already scaled
437483
/// appropriately.
438484
///
@@ -441,10 +487,10 @@ class AssetMapBitmap extends MapBitmap {
441487
/// - If both [width] and [height] are non-null, the image will have the
442488
/// specified dimensions, which might distort the original aspect ratio,
443489
/// similar to [BoxFit.fill].
444-
/// - If only one of `width` and `height` is non-null, then the output image
490+
/// - If only one of [width] and [height] is non-null, then the output image
445491
/// will be scaled to the associated width or height, and the other dimension
446492
/// will take whatever value is needed to maintain the image's original aspect
447-
/// ratio. These cases are simnilar to [BoxFit.fitWidth] and
493+
/// ratio. These cases are similar to [BoxFit.fitWidth] and
448494
/// [BoxFit.fitHeight], respectively.
449495
///
450496
/// If [width] or [height] is provided, [imagePixelRatio] value is ignored.
@@ -495,10 +541,10 @@ class AssetMapBitmap extends MapBitmap {
495541
}) : assert(assetName.isNotEmpty, 'The asset name must not be empty.'),
496542
assert(imagePixelRatio > 0.0,
497543
'The imagePixelRatio must be greater than 0.'),
498-
assert(bitmapScaling != MapBitmapScaling.noScaling || width == null,
499-
'If bitmapScaling is set to MapBitmapScaling.noScaling, width parameter cannot be used.'),
500-
assert(bitmapScaling != MapBitmapScaling.noScaling || height == null,
501-
'If bitmapScaling is set to MapBitmapScaling.noScaling, height parameter cannot be used.'),
544+
assert(bitmapScaling != MapBitmapScaling.none || width == null,
545+
'If bitmapScaling is set to MapBitmapScaling.none, width parameter cannot be used.'),
546+
assert(bitmapScaling != MapBitmapScaling.none || height == null,
547+
'If bitmapScaling is set to MapBitmapScaling.none, height parameter cannot be used.'),
502548
super._();
503549

504550
/// The type of the [BitmapDescriptor] object, used for the
@@ -524,17 +570,17 @@ class AssetMapBitmap extends MapBitmap {
524570
/// - If both [width] and [height] are non-null, the image will have the
525571
/// specified dimensions, which might distort the original aspect ratio,
526572
/// similar to [BoxFit.fill].
527-
/// - If only one of `width` and `height` is non-null, then the output image
573+
/// - If only one of [width] and [height] is non-null, then the output image
528574
/// will be scaled to the associated width or height, and the other
529575
/// dimension will take whatever value is needed to maintain the image's
530-
/// original aspect ratio. These cases are simnilar to [BoxFit.fitWidth] and
576+
/// original aspect ratio. These cases are similar to [BoxFit.fitWidth] and
531577
/// [BoxFit.fitHeight], respectively.
532578
///
533579
/// [bitmapScaling] controls the scaling behavior:
534580
/// - [MapBitmapScaling.auto] automatically upscales and downscales the image
535581
/// to match the device's pixel ratio or the specified dimensions,
536582
/// maintaining consistency across devices.
537-
/// - [MapBitmapScaling.noScaling] disables automatic scaling, which is
583+
/// - [MapBitmapScaling.none] disables automatic scaling, which is
538584
/// useful when performance is a concern or if the asset is already scaled
539585
/// appropriately.
540586
///
@@ -632,7 +678,7 @@ class AssetMapBitmap extends MapBitmap {
632678
/// - [MapBitmapScaling.auto] automatically upscales and downscales the image
633679
/// to match the device's pixel ratio or the specified dimensions,
634680
/// maintaining consistency across devices.
635-
/// - [MapBitmapScaling.noScaling] disables automatic scaling, which is
681+
/// - [MapBitmapScaling.none] disables automatic scaling, which is
636682
/// useful when performance is a concern or if the asset is already scaled
637683
/// appropriately.
638684
///
@@ -647,10 +693,10 @@ class AssetMapBitmap extends MapBitmap {
647693
/// - If both [width] and [height] are non-null, the image will have the
648694
/// specified dimensions, which might distort the original aspect ratio,
649695
/// similar to [BoxFit.fill].
650-
/// - If only one of `width` and `height` is non-null, then the output image
696+
/// - If only one of [width] and [height] is non-null, then the output image
651697
/// will be scaled to the associated width or height, and the other
652698
/// dimension will take whatever value is needed to maintain the image's
653-
/// original aspect ratio. These cases are simnilar to [BoxFit.fitWidth] and
699+
/// original aspect ratio. These cases are similar to [BoxFit.fitWidth] and
654700
/// [BoxFit.fitHeight], respectively.
655701
///
656702
/// The following example demonstrates how to create an [BytesMapBitmap] from
@@ -701,7 +747,7 @@ class BytesMapBitmap extends MapBitmap {
701747
/// - [MapBitmapScaling.auto] automatically upscales and downscales the image
702748
/// to match the device's pixel ratio or the specified dimensions,
703749
/// maintaining consistency across devices.
704-
/// - [MapBitmapScaling.noScaling] disables automatic scaling, which is
750+
/// - [MapBitmapScaling.none] disables automatic scaling, which is
705751
/// useful when performance is a concern or if the asset is already scaled
706752
/// appropriately.
707753
///
@@ -716,10 +762,10 @@ class BytesMapBitmap extends MapBitmap {
716762
/// - If both [width] and [height] are non-null, the image will have the
717763
/// specified dimensions, which might distort the original aspect ratio,
718764
/// similar to [BoxFit.fill].
719-
/// - If only one of `width` and `height` is non-null, then the output image
765+
/// - If only one of [width] and [height] is non-null, then the output image
720766
/// will be scaled to the associated width or height, and the other
721767
/// dimension will take whatever value is needed to maintain the image's
722-
/// original aspect ratio. These cases are simnilar to [BoxFit.fitWidth] and
768+
/// original aspect ratio. These cases are similar to [BoxFit.fitWidth] and
723769
/// [BoxFit.fitHeight], respectively.
724770
///
725771
/// Throws an [AssertionError] if [byteData] is empty or if incompatible
@@ -769,13 +815,12 @@ class BytesMapBitmap extends MapBitmap {
769815
}) : assert(byteData.isNotEmpty,
770816
'Cannot create BitmapDescriptor with empty byteData.'),
771817
assert(
772-
bitmapScaling != MapBitmapScaling.noScaling ||
773-
imagePixelRatio == null,
774-
'If bitmapScaling is set to MapBitmapScaling.noScaling, imagePixelRatio parameter cannot be used.'),
775-
assert(bitmapScaling != MapBitmapScaling.noScaling || width == null,
776-
'If bitmapScaling is set to MapBitmapScaling.noScaling, width parameter cannot be used.'),
777-
assert(bitmapScaling != MapBitmapScaling.noScaling || height == null,
778-
'If bitmapScaling is set to MapBitmapScaling.noScaling, height parameter cannot be used.'),
818+
bitmapScaling != MapBitmapScaling.none || imagePixelRatio == null,
819+
'If bitmapScaling is set to MapBitmapScaling.none, imagePixelRatio parameter cannot be used.'),
820+
assert(bitmapScaling != MapBitmapScaling.none || width == null,
821+
'If bitmapScaling is set to MapBitmapScaling.none, width parameter cannot be used.'),
822+
assert(bitmapScaling != MapBitmapScaling.none || height == null,
823+
'If bitmapScaling is set to MapBitmapScaling.none, height parameter cannot be used.'),
779824
super._(imagePixelRatio: imagePixelRatio ?? _naturalPixelRatio);
780825

781826
/// The type of the MapBitmap object, used for the JSON serialization.

packages/google_maps_flutter/google_maps_flutter_platform_interface/test/types/bitmap_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void main() {
411411
});
412412
});
413413

414-
group('$AssetMapBitmap', () {
414+
group('AssetMapBitmap', () {
415415
test('construct', () async {
416416
final BitmapDescriptor descriptor = AssetMapBitmap(
417417
'red_square.png',
@@ -548,7 +548,7 @@ void main() {
548548
// TODO(stuartmorgan): Investigate timeout on web.
549549
skip: kIsWeb);
550550

551-
group('$BytesMapBitmap', () {
551+
group('BytesMapBitmap', () {
552552
test('construct with empty byte array, throws assertion error', () {
553553
expect(() {
554554
BytesMapBitmap(Uint8List.fromList(<int>[]));

0 commit comments

Comments
 (0)