Skip to content

Commit 60d8f06

Browse files
Fix type mismatch in Geolocation API
Conditionally pass `PositionOptions` to native Geolocation methods only when non-null, resolving an assignment error in `packages/spark_web/lib/src/browser/geolocation.dart`.
1 parent 7d2c785 commit 60d8f06

File tree

1 file changed

+52
-22
lines changed

1 file changed

+52
-22
lines changed

packages/spark_web/lib/src/browser/geolocation.dart

Lines changed: 52 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,32 @@ class BrowserGeolocation implements iface.Geolocation {
2121
iface.PositionErrorCallback? errorCallback,
2222
iface.PositionOptions? options,
2323
]) {
24-
_native.getCurrentPosition(
25-
((web.GeolocationPosition pos) => successCallback(
26-
BrowserGeolocationPosition(pos),
27-
)).toJS,
28-
errorCallback == null
29-
? null
30-
: ((web.GeolocationPositionError err) => errorCallback(
31-
BrowserGeolocationPositionError(err),
32-
)).toJS,
33-
_createNativeOptions(options),
34-
);
24+
final nativeOptions = _createNativeOptions(options);
25+
26+
if (nativeOptions != null) {
27+
_native.getCurrentPosition(
28+
((web.GeolocationPosition pos) => successCallback(
29+
BrowserGeolocationPosition(pos),
30+
)).toJS,
31+
errorCallback == null
32+
? null
33+
: ((web.GeolocationPositionError err) => errorCallback(
34+
BrowserGeolocationPositionError(err),
35+
)).toJS,
36+
nativeOptions,
37+
);
38+
} else {
39+
_native.getCurrentPosition(
40+
((web.GeolocationPosition pos) => successCallback(
41+
BrowserGeolocationPosition(pos),
42+
)).toJS,
43+
errorCallback == null
44+
? null
45+
: ((web.GeolocationPositionError err) => errorCallback(
46+
BrowserGeolocationPositionError(err),
47+
)).toJS,
48+
);
49+
}
3550
}
3651

3752
@override
@@ -40,17 +55,32 @@ class BrowserGeolocation implements iface.Geolocation {
4055
iface.PositionErrorCallback? errorCallback,
4156
iface.PositionOptions? options,
4257
]) {
43-
return _native.watchPosition(
44-
((web.GeolocationPosition pos) => successCallback(
45-
BrowserGeolocationPosition(pos),
46-
)).toJS,
47-
errorCallback == null
48-
? null
49-
: ((web.GeolocationPositionError err) => errorCallback(
50-
BrowserGeolocationPositionError(err),
51-
)).toJS,
52-
_createNativeOptions(options),
53-
);
58+
final nativeOptions = _createNativeOptions(options);
59+
60+
if (nativeOptions != null) {
61+
return _native.watchPosition(
62+
((web.GeolocationPosition pos) => successCallback(
63+
BrowserGeolocationPosition(pos),
64+
)).toJS,
65+
errorCallback == null
66+
? null
67+
: ((web.GeolocationPositionError err) => errorCallback(
68+
BrowserGeolocationPositionError(err),
69+
)).toJS,
70+
nativeOptions,
71+
);
72+
} else {
73+
return _native.watchPosition(
74+
((web.GeolocationPosition pos) => successCallback(
75+
BrowserGeolocationPosition(pos),
76+
)).toJS,
77+
errorCallback == null
78+
? null
79+
: ((web.GeolocationPositionError err) => errorCallback(
80+
BrowserGeolocationPositionError(err),
81+
)).toJS,
82+
);
83+
}
5484
}
5585

5686
@override

0 commit comments

Comments
 (0)