From a8c4da22d9b978f127bdf4413692f25c219edec3 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 16 Jul 2019 09:12:21 -0700 Subject: [PATCH] add a kIsWeb constant to foundation (#36135) --- packages/flutter/lib/src/foundation/constants.dart | 9 +++++++++ .../flutter/test/foundation/constants_test.dart | 13 +++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 packages/flutter/test/foundation/constants_test.dart diff --git a/packages/flutter/lib/src/foundation/constants.dart b/packages/flutter/lib/src/foundation/constants.dart index 804ece0969..a78f9c20fe 100644 --- a/packages/flutter/lib/src/foundation/constants.dart +++ b/packages/flutter/lib/src/foundation/constants.dart @@ -38,3 +38,12 @@ const bool kDebugMode = !kReleaseMode && !kProfileMode; /// precision loss in calculations. Differences below this threshold are safe to /// disregard. const double precisionErrorTolerance = 1e-10; + +/// A constant that is true if the application was compiled to run on the web. +/// +/// This implementation takes advantage of the fact that JavaScript does not +/// support integers. In this environment, Dart's doubles and ints are +/// backed by the same kind of object. Thus a double `0.0` is identical +/// to an integer `0`. This is not true for Dart code running in AOT or on the +/// VM. +const bool kIsWeb = identical(0, 0.0); diff --git a/packages/flutter/test/foundation/constants_test.dart b/packages/flutter/test/foundation/constants_test.dart new file mode 100644 index 0000000000..e5dd97cf0b --- /dev/null +++ b/packages/flutter/test/foundation/constants_test.dart @@ -0,0 +1,13 @@ +// Copyright 2019 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +@TestOn('!chrome') // This test is not intended to run on the web. +import 'package:flutter/foundation.dart'; +import '../flutter_test_alternative.dart'; + +void main() { + test('isWeb is false for flutter tester', () { + expect(kIsWeb, false); + }); +}