Skip to content

Commit f7a668c

Browse files
authored
feat: Replace dart:html with dart:js_interop (#180)
1 parent 8cb812a commit f7a668c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

lib/src/testing/utils/detected_runtime.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
// limitations under the License.
1414

1515
import 'detected_runtime_stub.dart'
16-
if (dart.library.html) 'detected_runtime_html.dart';
16+
if (dart.library.js_interop) 'detected_runtime_js_interop.dart';
1717

1818
export 'detected_runtime_stub.dart'
19-
if (dart.library.html) 'detected_runtime_html.dart' show detectedRuntime;
19+
if (dart.library.js_interop) 'detected_runtime_js_interop.dart'
20+
show detectedRuntime;
2021

2122
/// Return `null` instead of [value] on Firefox.
2223
///

lib/src/testing/utils/detected_runtime_html.dart renamed to lib/src/testing/utils/detected_runtime_js_interop.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// ignore: avoid_web_libraries_in_flutter
16-
import 'dart:html' show window;
15+
import 'dart:js_interop';
16+
17+
@JS('window.navigator.userAgent')
18+
external String get userAgent;
1719

1820
/// Detected runtime based on [rendering engine][1], this is one of:
1921
/// * `'firefox'` (if rendering engine is `'gecko'`),
@@ -32,7 +34,7 @@ import 'dart:html' show window;
3234
///
3335
/// [1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Browser_detection_using_the_user_agent
3436
final String detectedRuntime = () {
35-
final ua = window.navigator.userAgent;
37+
final ua = userAgent;
3638

3739
if (ua.contains('Gecko/')) {
3840
return 'firefox';

0 commit comments

Comments
 (0)