15
15
///
16
16
/// Both methods are **disallowed** to be used at the same time.
17
17
///
18
- /// Example (Before):
19
- ///
20
- /// <head>
21
- /// <script>
22
- /// window.flutterConfiguration = {
23
- /// canvasKitBaseUrl: "https://example.com/my-custom-canvaskit/"
24
- /// };
25
- /// </script>
26
- /// </head>
27
- ///
28
- /// Example (After):
18
+ /// Example:
29
19
///
30
20
/// _flutter.loader.loadEntrypoint({
31
21
/// // ...
32
22
/// onEntrypointLoaded: async function(engineInitializer) {
33
23
/// let appRunner = await engineInitializer.initializeEngine({
34
- /// canvasKitBaseUrl: "https://example.com/my-custom-canvaskit/"
24
+ /// // JsFlutterConfiguration goes here...
25
+ /// canvasKitBaseUrl: "https://example.com/my-custom-canvaskit/",
35
26
/// });
36
27
/// appRunner.runApp();
37
28
/// }
38
29
/// });
39
30
///
31
+ /// Example of the **deprecated** style (this will issue a JS console warning!):
32
+ ///
33
+ /// <script>
34
+ /// window.flutterConfiguration = {
35
+ /// canvasKitBaseUrl: "https://example.com/my-custom-canvaskit/"
36
+ /// };
37
+ /// </script>
38
+ ///
40
39
/// Configuration properties supplied via this object override those supplied
41
40
/// using the corresponding environment variables. For example, if both the
42
41
/// `canvasKitBaseUrl` config entry and the `FLUTTER_WEB_CANVASKIT_URL`
@@ -55,7 +54,8 @@ import 'dom.dart';
55
54
const String _canvaskitVersion = '0.37.0' ;
56
55
57
56
/// The Web Engine configuration for the current application.
58
- FlutterConfiguration get configuration => _configuration ?? = FlutterConfiguration .fromJsGlobals (_jsConfiguration);
57
+ FlutterConfiguration get configuration =>
58
+ _configuration ?? = FlutterConfiguration .legacy (_jsConfiguration);
59
59
FlutterConfiguration ? _configuration;
60
60
61
61
/// Sets the given configuration as the current one.
@@ -76,23 +76,30 @@ class FlutterConfiguration {
76
76
77
77
/// Constucts a "tainted by JS globals" configuration object.
78
78
///
79
- /// This is deprecated, and warns the user about the new API.
80
- FlutterConfiguration .fromJsGlobals (JsFlutterConfiguration ? config) {
79
+ /// This configuration style is deprecated. It will warn the user about the
80
+ /// new API (if used)
81
+ FlutterConfiguration .legacy (JsFlutterConfiguration ? config) {
81
82
if (config != null ) {
82
- domWindow.console.warn ('window.flutterConfiguration is now deprecated.\n '
83
- 'Use engineInitializer.initializeEngine(config) instead.\n '
84
- 'See: https://docs.flutter.dev/development/platform-integration/web/initialization' );
85
- _createdFromJsGlobals = true ;
83
+ _usedLegacyConfigStyle = true ;
86
84
_configuration = config;
87
85
}
88
- if (_requestedRendererType != null ) {
89
- domWindow.console.warn ('window.flutterWebRenderer is now deprecated.\n '
90
- 'Use engineInitializer.initializeEngine(config) instead.\n '
91
- 'See: https://docs.flutter.dev/development/platform-integration/web/initialization' );
92
- }
86
+ // Warn the user of the deprecated behavior.
87
+ assert (() {
88
+ if (config != null ) {
89
+ domWindow.console.warn ('window.flutterConfiguration is now deprecated.\n '
90
+ 'Use engineInitializer.initializeEngine(config) instead.\n '
91
+ 'See: https://docs.flutter.dev/development/platform-integration/web/initialization' );
92
+ }
93
+ if (_requestedRendererType != null ) {
94
+ domWindow.console.warn ('window.flutterWebRenderer is now deprecated.\n '
95
+ 'Use engineInitializer.initializeEngine(config) instead.\n '
96
+ 'See: https://docs.flutter.dev/development/platform-integration/web/initialization' );
97
+ }
98
+ return true ;
99
+ }());
93
100
}
94
101
95
- bool _createdFromJsGlobals = false ;
102
+ bool _usedLegacyConfigStyle = false ;
96
103
JsFlutterConfiguration ? _configuration;
97
104
98
105
/// Sets a value for [_configuration] .
@@ -101,17 +108,18 @@ class FlutterConfiguration {
101
108
/// [initEngineServices] method.
102
109
///
103
110
/// This method throws an AssertionError, if the _configuration object has
104
- /// been set to anything non-null through the [FlutterConfiguration.fromJsGlobals ]
111
+ /// been set to anything non-null through the [FlutterConfiguration.legacy ]
105
112
/// constructor.
106
113
void setUserConfiguration (JsFlutterConfiguration ? configuration) {
107
114
if (configuration != null ) {
108
- assert (! _createdFromJsGlobals, 'Do not mix-and-match configuration styles. '
109
- 'Use engineInitializer.initializeEngine(config) instead of '
110
- 'window.flutterConfiguration.' );
115
+ assert (! _usedLegacyConfigStyle,
116
+ 'Use engineInitializer.initializeEngine(config) only. '
117
+ 'Using the (deprecated) window.flutterConfiguration and initializeEngine '
118
+ 'configuration simultaneously is not supported.' );
111
119
assert (_requestedRendererType == null || configuration.renderer == null ,
112
- 'Do not mix-and-match configuration styles . '
113
- 'Use engineInitializer.initializeEngine(config) instead of '
114
- 'window.flutterWebRenderer .' );
120
+ 'Use engineInitializer.initializeEngine(config) only . '
121
+ 'Using the (deprecated) window.flutterWebRenderer and initializeEngine '
122
+ 'configuration simultaneously is not supported .' );
115
123
_configuration = configuration;
116
124
}
117
125
}
0 commit comments