Skip to content

Commit

Permalink
fix: deprecated color methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jokerttu committed Feb 7, 2025
1 parent 4d25177 commit 3c96f79
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void main() {
polylines[0]!.options.points![1].longitude, closeTo(25.929471, 0.01));
expect(polylines[0]!.options.clickable, true);
expect(polylines[0]!.options.geodesic, true);
expect(polylines[0]!.options.strokeColor!.value, Colors.red.value);
expect(polylines[0]!.options.strokeColor!, Colors.red);
expect(polylines[0]!.options.strokeWidth, 5.0);

/// iOS doesn't have strokeJointTypes
Expand Down Expand Up @@ -343,8 +343,7 @@ void main() {
expect(receivedPolylines.length, 1);
expect(receivedPolylines[0]!.options.geodesic, false);
expect(receivedPolylines[0]!.options.clickable, false);
expect(
receivedPolylines[0]!.options.strokeColor!.value, Colors.black.value);
expect(receivedPolylines[0]!.options.strokeColor!, Colors.black);
expect(receivedPolylines[0]!.options.strokeWidth, 10.0);

/// iOS doesn't have strokeJointTypes
Expand Down
12 changes: 6 additions & 6 deletions example/lib/pages/circles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class _CirclesPageState extends ExamplePageState<CirclesPage> {
Future<void> _setFillColor() async {
final Color oldColor = _selectedCircle!.options.fillColor;
final Color newColor = _colors.elementAtOrNull(
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
_colors[0];

await _updateSelectedCircleWithOptions(
Expand All @@ -151,21 +151,21 @@ class _CirclesPageState extends ExamplePageState<CirclesPage> {
Future<void> _setStrokeColor() async {
final Color oldColor = _selectedCircle!.options.strokeColor;
final Color newColor = _colors.elementAtOrNull(
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
_colors[0];

await _updateSelectedCircleWithOptions(
_selectedCircle!.options.copyWith(strokeColor: newColor));
}

String _colorName(Color? color) {
if (color?.value == Colors.black.value) {
if (color == Colors.black) {
return 'Black';
} else if (color?.value == Colors.red.value) {
} else if (color == Colors.red) {
return 'Red';
} else if (color?.value == Colors.green.value) {
} else if (color == Colors.green) {
return 'Green';
} else if (color?.value == Colors.blue.value) {
} else if (color == Colors.blue) {
return 'Blue';
} else {
return 'null';
Expand Down
12 changes: 6 additions & 6 deletions example/lib/pages/polygons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class _PolygonsPageState extends ExamplePageState<PolygonsPage> {
Future<void> _setFillColor() async {
final Color oldColor = _selectedPolygon!.options.fillColor;
final Color newColor = _colors.elementAtOrNull(
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
_colors[0];

await _updateSelectedPolygonWithOptions(
Expand All @@ -197,21 +197,21 @@ class _PolygonsPageState extends ExamplePageState<PolygonsPage> {
Future<void> _setStrokeColor() async {
final Color oldColor = _selectedPolygon!.options.strokeColor;
final Color newColor = _colors.elementAtOrNull(
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
_colors[0];

await _updateSelectedPolygonWithOptions(
_selectedPolygon!.options.copyWith(strokeColor: newColor));
}

String _colorName(Color? color) {
if (color?.value == Colors.black.value) {
if (color == Colors.black) {
return 'Black';
} else if (color?.value == Colors.red.value) {
} else if (color == Colors.red) {
return 'Red';
} else if (color?.value == Colors.green.value) {
} else if (color == Colors.green) {
return 'Green';
} else if (color?.value == Colors.blue.value) {
} else if (color == Colors.blue) {
return 'Blue';
} else {
return 'null';
Expand Down
10 changes: 5 additions & 5 deletions example/lib/pages/polylines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class _PolylinesPageState extends ExamplePageState<PolylinesPage> {
Future<void> _setStrokeColor() async {
final Color oldColor = _selectedPolyline!.options.strokeColor!;
final Color newColor = _colors.elementAtOrNull(
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
_colors[0];

await _updateSelectedPolylineWithOptions(
Expand All @@ -159,13 +159,13 @@ class _PolylinesPageState extends ExamplePageState<PolylinesPage> {
}

String _colorName(Color? color) {
if (color?.value == Colors.black.value) {
if (color == Colors.black) {
return 'Black';
} else if (color?.value == Colors.red.value) {
} else if (color == Colors.red) {
return 'Red';
} else if (color?.value == Colors.green.value) {
} else if (color == Colors.green) {
return 'Green';
} else if (color?.value == Colors.blue.value) {
} else if (color == Colors.blue) {
return 'Blue';
} else {
return 'null';
Expand Down
3 changes: 2 additions & 1 deletion example/lib/widgets/page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ abstract class ExamplePageState<T extends ExamplePage> extends State<T>
child: AnimatedBuilder(
animation: _controller,
builder: (BuildContext context, Widget? child) => Container(
color: Colors.black.withOpacity(_controller.value * 0.5)))),
color: Colors.black.withAlpha(
(255.0 * _controller.value * 0.5).round())))),
// Overlay content
SlideTransition(
position: _overlayOffsetAnimation,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/method_channel/convert/circle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ extension ConvertCircleOptions on CircleOptions {
strokePattern:
strokePattern.map((PatternItem pi) => pi.toDto()).toList(),
clickable: clickable,
fillColor: fillColor.value,
strokeColor: strokeColor.value,
fillColor: colorToInt(fillColor)!,
strokeColor: colorToInt(strokeColor)!,
strokeWidth: strokeWidth,
visible: visible,
zIndex: zIndex);
Expand Down
27 changes: 27 additions & 0 deletions lib/src/method_channel/convert/color.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2023 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import 'dart:ui';

int? colorToInt(Color? color) {
if (color == null) {
return null;
}

int floatToInt8(double x) => (x * 255.0).round() & 0xff;

return (floatToInt8(color.a) << 24) |
(floatToInt8(color.r) << 16) |
(floatToInt8(color.g) << 8) |
(floatToInt8(color.b));
}
1 change: 1 addition & 0 deletions lib/src/method_channel/convert/convert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

export 'camera.dart';
export 'circle.dart';
export 'color.dart';
export 'destinations.dart';
export 'latlng.dart';
export 'latlng_bounds.dart';
Expand Down
4 changes: 2 additions & 2 deletions lib/src/method_channel/convert/polygon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ extension ConvertPolygonOptions on PolygonOptions {
PolygonHoleDto(points: e.map((LatLng e) => e.toDto()).toList()))
.toList(),
clickable: clickable,
fillColor: fillColor.value,
fillColor: colorToInt(fillColor)!,
geodesic: geodesic,
strokeColor: strokeColor.value,
strokeColor: colorToInt(strokeColor)!,
strokeWidth: strokeWidth,
visible: visible,
zIndex: zIndex);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/method_channel/convert/polyline.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension ConvertPolylineOptions on PolylineOptions {
points: points?.map((LatLng point) => point.toDto()).toList(),
clickable: clickable,
geodesic: geodesic,
strokeColor: strokeColor?.value,
strokeColor: colorToInt(strokeColor),
strokeJointType: strokeJointType?.toStrokeJointTypeDto(),
strokePattern:
strokePattern?.map((PatternItem pi) => pi.toDto()).toList(),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/types/circles.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ class CircleOptions {
position == other.position &&
radius == other.radius &&
strokeWidth == other.strokeWidth &&
strokeColor.value == other.strokeColor.value &&
strokeColor == other.strokeColor &&
listEquals(strokePattern, other.strokePattern) &&
fillColor.value == other.fillColor.value &&
fillColor == other.fillColor &&
clickable == other.clickable &&
visible == other.visible &&
zIndex == other.zIndex;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/types/polygons.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ class PolygonOptions {
listEquals(points, other.points) &&
const DeepCollectionEquality().equals(holes, other.holes) &&
clickable == other.clickable &&
fillColor.value == other.fillColor.value &&
fillColor == other.fillColor &&
geodesic == other.geodesic &&
strokeColor.value == other.strokeColor.value &&
strokeColor == other.strokeColor &&
strokeWidth == other.strokeWidth &&
visible == other.visible &&
zIndex == other.zIndex;
Expand All @@ -164,9 +164,9 @@ class PolygonOptions {
points.hashCode,
holes.hashCode,
clickable.hashCode,
fillColor.value.hashCode,
fillColor.hashCode,
geodesic.hashCode,
strokeColor.value.hashCode,
strokeColor.hashCode,
strokeWidth.hashCode,
visible.hashCode,
zIndex.hashCode);
Expand Down
4 changes: 2 additions & 2 deletions lib/src/types/polylines.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class PolylineOptions {
listEquals(points, other.points) &&
clickable == other.clickable &&
geodesic == other.geodesic &&
strokeColor?.value == other.strokeColor?.value &&
strokeColor == other.strokeColor &&
strokeJointType == other.strokeJointType &&
listEquals(strokePattern, other.strokePattern) &&
strokeWidth == other.strokeWidth &&
Expand All @@ -155,7 +155,7 @@ class PolylineOptions {
points.hashCode,
clickable.hashCode,
geodesic.hashCode,
strokeColor?.value.hashCode,
strokeColor?.hashCode,
strokeJointType.hashCode,
strokePattern.hashCode,
strokeWidth.hashCode,
Expand Down
12 changes: 6 additions & 6 deletions test/navigation_polygons_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ void main() {
])
],
clickable: true,
fillColor: Colors.amber.value,
fillColor: colorToInt(Colors.amber)!,
geodesic: true,
strokeColor: Colors.blue.value,
strokeColor: colorToInt(Colors.blue)!,
strokeWidth: 4,
visible: true,
zIndex: 3));
Expand Down Expand Up @@ -101,9 +101,9 @@ void main() {

// Other parameters
expect(converted.options.clickable, true);
expect(converted.options.fillColor, 0xFFFFC107);
expect(converted.options.fillColor, colorToInt(Colors.amber));
expect(converted.options.geodesic, true);
expect(converted.options.strokeColor, 0xFF2196F3);
expect(converted.options.strokeColor, colorToInt(Colors.blue));
expect(converted.options.strokeWidth, 4);
expect(converted.options.visible, true);
expect(converted.options.zIndex, 3);
Expand Down Expand Up @@ -135,9 +135,9 @@ void main() {

// Other parameters
expect(converted.options.clickable, true);
expect(converted.options.fillColor.value, 0xFFFFC107);
expect(converted.options.fillColor, Colors.amber);
expect(converted.options.geodesic, true);
expect(converted.options.strokeColor.value, 0xFF2196F3);
expect(converted.options.strokeColor, Colors.blue);
expect(converted.options.strokeWidth, 4);
expect(converted.options.visible, true);
expect(converted.options.zIndex, 3);
Expand Down

0 comments on commit 3c96f79

Please sign in to comment.