Skip to content

Commit c0dddac

Browse files
authored
Fix is canvas kit bool (#116944)
* isCanvasKit implement and test * isCanvasKit implement and test * ++ * forgot license * make isCanvasKit a getter * addressed comments * forgot to change names of integration test files * typo * simplified tests * comments
1 parent 49f3ca4 commit c0dddac

10 files changed

+85
-3
lines changed

dev/bots/test.dart

+5
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,11 @@ Future<void> _runWebLongRunningTests() async {
11771177
() => _runWebE2eTest('url_strategy_integration', buildMode: 'profile', renderer: 'canvaskit'),
11781178
() => _runWebE2eTest('url_strategy_integration', buildMode: 'release', renderer: 'html'),
11791179

1180+
// This test doesn't do anything interesting w.r.t. rendering, so we don't run the full build mode x renderer matrix.
1181+
() => _runWebE2eTest('capabilities_integration_canvaskit', buildMode: 'debug', renderer: 'auto'),
1182+
() => _runWebE2eTest('capabilities_integration_canvaskit', buildMode: 'profile', renderer: 'canvaskit'),
1183+
() => _runWebE2eTest('capabilities_integration_html', buildMode: 'release', renderer: 'html'),
1184+
11801185
() => _runWebTreeshakeTest(),
11811186

11821187
() => _runFlutterDriverWebTest(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/foundation.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:integration_test/integration_test.dart';
8+
9+
void main() {
10+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
11+
12+
testWidgets('isCanvasKit returns true in CanvasKit mode', (WidgetTester tester) async {
13+
await tester.pumpAndSettle();
14+
expect(isCanvasKit, true);
15+
});
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:integration_test/integration_test_driver.dart' as test;
6+
7+
Future<void> main() async => test.integrationDriver();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:flutter/foundation.dart';
6+
import 'package:flutter_test/flutter_test.dart';
7+
import 'package:integration_test/integration_test.dart';
8+
void main() {
9+
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
10+
11+
testWidgets('isCanvasKit returns false in HTML mode', (WidgetTester tester) async {
12+
await tester.pumpAndSettle();
13+
expect(isCanvasKit, false);
14+
});
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:integration_test/integration_test_driver.dart' as test;
6+
7+
Future<void> main() async => test.integrationDriver();

packages/flutter/lib/foundation.dart

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export 'src/foundation/assertions.dart';
2424
export 'src/foundation/basic_types.dart';
2525
export 'src/foundation/binding.dart';
2626
export 'src/foundation/bitfield.dart';
27+
export 'src/foundation/capabilities.dart';
2728
export 'src/foundation/change_notifier.dart';
2829
export 'src/foundation/collections.dart';
2930
export 'src/foundation/consolidate_response.dart';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// The dart:io implementation of [isCanvasKit].
6+
///
7+
/// This bool shouldn't be used outside of web.
8+
bool get isCanvasKit {
9+
throw UnimplementedError('isCanvasKit is not implemented for dart:io.');
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import 'package:js/js.dart';
6+
7+
// This value is set by the engine. It is used to determine if the application is
8+
// using canvaskit.
9+
@JS('window.flutterCanvasKit')
10+
external Object? get _windowFlutterCanvasKit;
11+
12+
/// The web implementation of [isCanvasKit]
13+
bool get isCanvasKit => _windowFlutterCanvasKit != null;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import '_capabilities_io.dart'
6+
if (dart.library.js_util) '_capabilities_web.dart' as capabilities;
7+
8+
/// Returns true if the application is using CanvasKit.
9+
///
10+
/// Only to be used for web.
11+
bool get isCanvasKit => capabilities.isCanvasKit;

packages/flutter/lib/src/foundation/constants.dart

-3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,3 @@ const double precisionErrorTolerance = 1e-10;
6969

7070
/// A constant that is true if the application was compiled to run on the web.
7171
const bool kIsWeb = bool.fromEnvironment('dart.library.js_util');
72-
73-
/// A constant that is true if the application is using canvasKit
74-
const bool isCanvasKit = bool.fromEnvironment('FLUTTER_WEB_USE_SKIA');

0 commit comments

Comments
 (0)