Skip to content

Commit 3c96f79

Browse files
committed
fix: deprecated color methods
1 parent 4d25177 commit 3c96f79

File tree

14 files changed

+68
-40
lines changed

14 files changed

+68
-40
lines changed

example/integration_test/t08_marker_polygon_polyline_circle_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ void main() {
308308
polylines[0]!.options.points![1].longitude, closeTo(25.929471, 0.01));
309309
expect(polylines[0]!.options.clickable, true);
310310
expect(polylines[0]!.options.geodesic, true);
311-
expect(polylines[0]!.options.strokeColor!.value, Colors.red.value);
311+
expect(polylines[0]!.options.strokeColor!, Colors.red);
312312
expect(polylines[0]!.options.strokeWidth, 5.0);
313313

314314
/// iOS doesn't have strokeJointTypes
@@ -343,8 +343,7 @@ void main() {
343343
expect(receivedPolylines.length, 1);
344344
expect(receivedPolylines[0]!.options.geodesic, false);
345345
expect(receivedPolylines[0]!.options.clickable, false);
346-
expect(
347-
receivedPolylines[0]!.options.strokeColor!.value, Colors.black.value);
346+
expect(receivedPolylines[0]!.options.strokeColor!, Colors.black);
348347
expect(receivedPolylines[0]!.options.strokeWidth, 10.0);
349348

350349
/// iOS doesn't have strokeJointTypes

example/lib/pages/circles.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class _CirclesPageState extends ExamplePageState<CirclesPage> {
141141
Future<void> _setFillColor() async {
142142
final Color oldColor = _selectedCircle!.options.fillColor;
143143
final Color newColor = _colors.elementAtOrNull(
144-
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
144+
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
145145
_colors[0];
146146

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

157157
await _updateSelectedCircleWithOptions(
158158
_selectedCircle!.options.copyWith(strokeColor: newColor));
159159
}
160160

161161
String _colorName(Color? color) {
162-
if (color?.value == Colors.black.value) {
162+
if (color == Colors.black) {
163163
return 'Black';
164-
} else if (color?.value == Colors.red.value) {
164+
} else if (color == Colors.red) {
165165
return 'Red';
166-
} else if (color?.value == Colors.green.value) {
166+
} else if (color == Colors.green) {
167167
return 'Green';
168-
} else if (color?.value == Colors.blue.value) {
168+
} else if (color == Colors.blue) {
169169
return 'Blue';
170170
} else {
171171
return 'null';

example/lib/pages/polygons.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ class _PolygonsPageState extends ExamplePageState<PolygonsPage> {
187187
Future<void> _setFillColor() async {
188188
final Color oldColor = _selectedPolygon!.options.fillColor;
189189
final Color newColor = _colors.elementAtOrNull(
190-
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
190+
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
191191
_colors[0];
192192

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

203203
await _updateSelectedPolygonWithOptions(
204204
_selectedPolygon!.options.copyWith(strokeColor: newColor));
205205
}
206206

207207
String _colorName(Color? color) {
208-
if (color?.value == Colors.black.value) {
208+
if (color == Colors.black) {
209209
return 'Black';
210-
} else if (color?.value == Colors.red.value) {
210+
} else if (color == Colors.red) {
211211
return 'Red';
212-
} else if (color?.value == Colors.green.value) {
212+
} else if (color == Colors.green) {
213213
return 'Green';
214-
} else if (color?.value == Colors.blue.value) {
214+
} else if (color == Colors.blue) {
215215
return 'Blue';
216216
} else {
217217
return 'null';

example/lib/pages/polylines.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class _PolylinesPageState extends ExamplePageState<PolylinesPage> {
143143
Future<void> _setStrokeColor() async {
144144
final Color oldColor = _selectedPolyline!.options.strokeColor!;
145145
final Color newColor = _colors.elementAtOrNull(
146-
_colors.indexWhere((Color e) => e.value == oldColor.value) + 1) ??
146+
_colors.indexWhere((Color e) => e == oldColor) + 1) ??
147147
_colors[0];
148148

149149
await _updateSelectedPolylineWithOptions(
@@ -159,13 +159,13 @@ class _PolylinesPageState extends ExamplePageState<PolylinesPage> {
159159
}
160160

161161
String _colorName(Color? color) {
162-
if (color?.value == Colors.black.value) {
162+
if (color == Colors.black) {
163163
return 'Black';
164-
} else if (color?.value == Colors.red.value) {
164+
} else if (color == Colors.red) {
165165
return 'Red';
166-
} else if (color?.value == Colors.green.value) {
166+
} else if (color == Colors.green) {
167167
return 'Green';
168-
} else if (color?.value == Colors.blue.value) {
168+
} else if (color == Colors.blue) {
169169
return 'Blue';
170170
} else {
171171
return 'null';

example/lib/widgets/page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ abstract class ExamplePageState<T extends ExamplePage> extends State<T>
118118
child: AnimatedBuilder(
119119
animation: _controller,
120120
builder: (BuildContext context, Widget? child) => Container(
121-
color: Colors.black.withOpacity(_controller.value * 0.5)))),
121+
color: Colors.black.withAlpha(
122+
(255.0 * _controller.value * 0.5).round())))),
122123
// Overlay content
123124
SlideTransition(
124125
position: _overlayOffsetAnimation,

lib/src/method_channel/convert/circle.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ extension ConvertCircleOptions on CircleOptions {
6666
strokePattern:
6767
strokePattern.map((PatternItem pi) => pi.toDto()).toList(),
6868
clickable: clickable,
69-
fillColor: fillColor.value,
70-
strokeColor: strokeColor.value,
69+
fillColor: colorToInt(fillColor)!,
70+
strokeColor: colorToInt(strokeColor)!,
7171
strokeWidth: strokeWidth,
7272
visible: visible,
7373
zIndex: zIndex);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
import 'dart:ui';
15+
16+
int? colorToInt(Color? color) {
17+
if (color == null) {
18+
return null;
19+
}
20+
21+
int floatToInt8(double x) => (x * 255.0).round() & 0xff;
22+
23+
return (floatToInt8(color.a) << 24) |
24+
(floatToInt8(color.r) << 16) |
25+
(floatToInt8(color.g) << 8) |
26+
(floatToInt8(color.b));
27+
}

lib/src/method_channel/convert/convert.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
export 'camera.dart';
1616
export 'circle.dart';
17+
export 'color.dart';
1718
export 'destinations.dart';
1819
export 'latlng.dart';
1920
export 'latlng_bounds.dart';

lib/src/method_channel/convert/polygon.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ extension ConvertPolygonOptions on PolygonOptions {
3838
PolygonHoleDto(points: e.map((LatLng e) => e.toDto()).toList()))
3939
.toList(),
4040
clickable: clickable,
41-
fillColor: fillColor.value,
41+
fillColor: colorToInt(fillColor)!,
4242
geodesic: geodesic,
43-
strokeColor: strokeColor.value,
43+
strokeColor: colorToInt(strokeColor)!,
4444
strokeWidth: strokeWidth,
4545
visible: visible,
4646
zIndex: zIndex);

lib/src/method_channel/convert/polyline.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension ConvertPolylineOptions on PolylineOptions {
3535
points: points?.map((LatLng point) => point.toDto()).toList(),
3636
clickable: clickable,
3737
geodesic: geodesic,
38-
strokeColor: strokeColor?.value,
38+
strokeColor: colorToInt(strokeColor),
3939
strokeJointType: strokeJointType?.toStrokeJointTypeDto(),
4040
strokePattern:
4141
strokePattern?.map((PatternItem pi) => pi.toDto()).toList(),

0 commit comments

Comments
 (0)