@@ -31,107 +31,72 @@ void _updateWindowMetrics(
3131 double systemGestureInsetBottom,
3232 double systemGestureInsetLeft,
3333) {
34- assert (PlatformDispatcher .instance._screens[screenId] != null );
35- final ViewConfiguration previousConfiguration =
36- PlatformDispatcher .instance._viewConfigurations[id] ?? ViewConfiguration (screen: PlatformDispatcher .instance._screens[screenId]);
37- PlatformDispatcher .instance._viewConfigurations[id] = previousConfiguration.copyWith (
38- screen: PlatformDispatcher .instance._screens[screenId],
39- geometry: Rect .fromLTWH (left, top, width, height),
40- depth: depth,
41- viewPadding: WindowPadding ._(
42- top: viewPaddingTop,
43- right: viewPaddingRight,
44- bottom: viewPaddingBottom,
45- left: viewPaddingLeft,
46- ),
47- viewInsets: WindowPadding ._(
48- top: viewInsetTop,
49- right: viewInsetRight,
50- bottom: viewInsetBottom,
51- left: viewInsetLeft,
52- ),
53- padding: WindowPadding ._(
54- top: math.max (0.0 , viewPaddingTop - viewInsetTop),
55- right: math.max (0.0 , viewPaddingRight - viewInsetRight),
56- bottom: math.max (0.0 , viewPaddingBottom - viewInsetBottom),
57- left: math.max (0.0 , viewPaddingLeft - viewInsetLeft),
58- ),
59- systemGestureInsets: WindowPadding ._(
60- top: math.max (0.0 , systemGestureInsetTop),
61- right: math.max (0.0 , systemGestureInsetRight),
62- bottom: math.max (0.0 , systemGestureInsetBottom),
63- left: math.max (0.0 , systemGestureInsetLeft),
64- ),
65- );
66- if (! PlatformDispatcher .instance._views.containsKey (id)) {
67- PlatformDispatcher .instance._views[id] = FlutterWindow ._(windowId: id, platformDispatcher: PlatformDispatcher .instance);
68- }
69- _invoke (
70- PlatformDispatcher .instance.onMetricsChanged,
71- PlatformDispatcher .instance._onMetricsChangedZone,
34+ PlatformDispatcher .instance._updateViewMetrics (
35+ id,
36+ screenId,
37+ left,
38+ top,
39+ width,
40+ height,
41+ depth,
42+ viewPaddingTop,
43+ viewPaddingRight,
44+ viewPaddingBottom,
45+ viewPaddingLeft,
46+ viewInsetTop,
47+ viewInsetRight,
48+ viewInsetBottom,
49+ viewInsetLeft,
50+ systemGestureInsetTop,
51+ systemGestureInsetRight,
52+ systemGestureInsetBottom,
53+ systemGestureInsetLeft,
7254 );
7355}
7456
7557@pragma ('vm:entry-point' )
7658// ignore: unused_element
7759void _updateScreenMetrics (
78- Object /*!*/ id,
79- String /*!*/ screenName,
80- double /*!*/ left,
81- double /*!*/ top,
82- double /*!*/ width,
83- double /*!*/ height,
84- double /*!*/ devicePixelRatio,
85- double /*!*/ viewPaddingTop,
86- double /*!*/ viewPaddingRight,
87- double /*!*/ viewPaddingBottom,
88- double /*!*/ viewPaddingLeft,
89- double /*!*/ viewInsetTop,
90- double /*!*/ viewInsetRight,
91- double /*!*/ viewInsetBottom,
92- double /*!*/ viewInsetLeft,
93- double /*!*/ systemGestureInsetTop,
94- double /*!*/ systemGestureInsetRight,
95- double /*!*/ systemGestureInsetBottom,
96- double /*!*/ systemGestureInsetLeft,
60+ Object id,
61+ String screenName,
62+ double left,
63+ double top,
64+ double width,
65+ double height,
66+ double devicePixelRatio,
67+ double viewPaddingTop,
68+ double viewPaddingRight,
69+ double viewPaddingBottom,
70+ double viewPaddingLeft,
71+ double viewInsetTop,
72+ double viewInsetRight,
73+ double viewInsetBottom,
74+ double viewInsetLeft,
75+ double systemGestureInsetTop,
76+ double systemGestureInsetRight,
77+ double systemGestureInsetBottom,
78+ double systemGestureInsetLeft,
9779) {
98- final ScreenConfiguration previousConfiguration =
99- PlatformDispatcher .instance._screenConfigurations[id] ?? const ScreenConfiguration ();
100- PlatformDispatcher .instance._screenConfigurations[id] = previousConfiguration.copyWith (
101- screenName: screenName,
102- geometry: Rect .fromLTWH (left, top, width, height),
103- devicePixelRatio: devicePixelRatio,
104- viewPadding: WindowPadding ._(
105- top: viewPaddingTop,
106- right: viewPaddingRight,
107- bottom: viewPaddingBottom,
108- left: viewPaddingLeft,
109- ),
110- viewInsets: WindowPadding ._(
111- top: viewInsetTop,
112- right: viewInsetRight,
113- bottom: viewInsetBottom,
114- left: viewInsetLeft,
115- ),
116- padding: WindowPadding ._(
117- top: math.max (0.0 , viewPaddingTop - viewInsetTop),
118- right: math.max (0.0 , viewPaddingRight - viewInsetRight),
119- bottom: math.max (0.0 , viewPaddingBottom - viewInsetBottom),
120- left: math.max (0.0 , viewPaddingLeft - viewInsetLeft),
121- ),
122- systemGestureInsets: WindowPadding ._(
123- top: math.max (0.0 , systemGestureInsetTop),
124- right: math.max (0.0 , systemGestureInsetRight),
125- bottom: math.max (0.0 , systemGestureInsetBottom),
126- left: math.max (0.0 , systemGestureInsetLeft),
127- ),
128- );
129- if (! PlatformDispatcher .instance._screens.containsKey (id)) {
130- PlatformDispatcher .instance._screens[id] = Screen ._(screenId: id, platformDispatcher: PlatformDispatcher .instance);
131- }
132- _invoke (
133- PlatformDispatcher .instance.onMetricsChanged,
134- PlatformDispatcher .instance._onMetricsChangedZone,
80+ PlatformDispatcher .instance._updateScreenMetrics (
81+ id,
82+ screenName,
83+ left,
84+ top,
85+ width,
86+ height,
87+ devicePixelRatio,
88+ viewPaddingTop,
89+ viewPaddingRight,
90+ viewPaddingBottom,
91+ viewPaddingLeft,
92+ viewInsetTop,
93+ viewInsetRight,
94+ viewInsetBottom,
95+ viewInsetLeft,
96+ systemGestureInsetTop,
97+ systemGestureInsetRight,
98+ systemGestureInsetBottom,
99+ systemGestureInsetLeft,
135100 );
136101}
137102
@@ -151,69 +116,13 @@ _LocaleClosure? _getLocaleClosure() => _localeClosure;
151116@pragma ('vm:entry-point' )
152117// ignore: unused_element
153118void _updateLocales (List <String > locales) {
154- const int stringsPerLocale = 4 ;
155- final int numLocales = locales.length ~ / stringsPerLocale;
156- final PlatformConfiguration previousConfiguration = PlatformDispatcher .instance.configuration;
157- final List <Locale > newLocales = < Locale > [];
158- bool localesDiffer = numLocales != previousConfiguration.locales.length;
159- for (int localeIndex = 0 ; localeIndex < numLocales; localeIndex++ ) {
160- final String countryCode = locales[localeIndex * stringsPerLocale + 1 ];
161- final String scriptCode = locales[localeIndex * stringsPerLocale + 2 ];
162-
163- newLocales.add (Locale .fromSubtags (
164- languageCode: locales[localeIndex * stringsPerLocale],
165- countryCode: countryCode.isEmpty ? null : countryCode,
166- scriptCode: scriptCode.isEmpty ? null : scriptCode,
167- ));
168- if (! localesDiffer && newLocales.last != previousConfiguration.locales[localeIndex]) {
169- localesDiffer = true ;
170- }
171- }
172- if (! localesDiffer) {
173- return ;
174- }
175- PlatformDispatcher .instance._configuration = previousConfiguration.copyWith (
176- locales: newLocales,
177- );
178- _invoke (
179- PlatformDispatcher .instance.onPlatformConfigurationChanged,
180- PlatformDispatcher .instance._onPlatformConfigurationChangedZone,
181- );
182- _invoke (
183- PlatformDispatcher .instance.onLocaleChanged,
184- PlatformDispatcher .instance._onLocaleChangedZone,
185- );
119+ PlatformDispatcher .instance._updateLocales (locales);
186120}
187121
188122@pragma ('vm:entry-point' )
189123// ignore: unused_element
190124void _updatePlatformResolvedLocale (List <String > localeData) {
191- if (localeData.length != 4 ) {
192- return ;
193- }
194- final String countryCode = localeData[1 ];
195- final String scriptCode = localeData[2 ];
196- final PlatformConfiguration previousConfiguration = PlatformDispatcher .instance.configuration;
197- final Locale resolvedLocale = Locale .fromSubtags (
198- languageCode: localeData[0 ],
199- countryCode: countryCode.isEmpty ? null : countryCode,
200- scriptCode: scriptCode.isEmpty ? null : scriptCode,
201- );
202- if (previousConfiguration.platformResolvedLocale == resolvedLocale) {
203- return ;
204- }
205-
206- PlatformDispatcher .instance._configuration = previousConfiguration.copyWith (
207- platformResolvedLocale: resolvedLocale,
208- );
209- _invoke (
210- PlatformDispatcher .instance.onPlatformConfigurationChanged,
211- PlatformDispatcher .instance._onPlatformConfigurationChangedZone,
212- );
213- _invoke (
214- PlatformDispatcher .instance.onLocaleChanged,
215- PlatformDispatcher .instance._onLocaleChangedZone,
216- );
125+ PlatformDispatcher .instance._updatePlatformResolvedLocale (localeData);
217126}
218127
219128@pragma ('vm:entry-point' )
@@ -223,115 +132,32 @@ void _updateUserSettingsData(String jsonData) {
223132 if (data.isEmpty) {
224133 return ;
225134 }
226-
227- final double textScaleFactor = (data['textScaleFactor' ] as num ).toDouble ();
228- final bool alwaysUse24HourFormat = data['alwaysUse24HourFormat' ] as bool ;
229- final Brightness platformBrightness =
230- data['platformBrightness' ] as String == 'dark' ? Brightness .dark : Brightness .light;
231- final PlatformConfiguration previousConfiguration = PlatformDispatcher .instance.configuration;
232- final bool platformBrightnessChanged =
233- previousConfiguration.platformBrightness != platformBrightness;
234- final bool textScaleFactorChanged = previousConfiguration.textScaleFactor != textScaleFactor;
235- final bool alwaysUse24HourFormatChanged =
236- previousConfiguration.alwaysUse24HourFormat != alwaysUse24HourFormat;
237- if (! platformBrightnessChanged && ! textScaleFactorChanged && ! alwaysUse24HourFormatChanged) {
238- return ;
239- }
240- PlatformDispatcher .instance._configuration = previousConfiguration.copyWith (
241- textScaleFactor: textScaleFactor,
242- alwaysUse24HourFormat: alwaysUse24HourFormat,
243- platformBrightness: platformBrightness,
244- );
245- _invoke (
246- PlatformDispatcher .instance.onPlatformConfigurationChanged,
247- PlatformDispatcher .instance._onPlatformConfigurationChangedZone,
248- );
249- if (textScaleFactorChanged) {
250- _invoke (
251- PlatformDispatcher .instance.onTextScaleFactorChanged,
252- PlatformDispatcher .instance._onTextScaleFactorChangedZone,
253- );
254- }
255- if (platformBrightnessChanged) {
256- _invoke (
257- PlatformDispatcher .instance.onPlatformBrightnessChanged,
258- PlatformDispatcher .instance._onPlatformBrightnessChangedZone,
259- );
260- }
135+ PlatformDispatcher .instance._updateUserSettingsData (data);
261136}
262137
263138@pragma ('vm:entry-point' )
264139// ignore: unused_element
265140void _updateLifecycleState (String state) {
266- // We do not update the state if the state has already been used to initialize
267- // the lifecycleState.
268- if (! PlatformDispatcher .instance._initialLifecycleStateAccessed)
269- PlatformDispatcher .instance._initialLifecycleState = state;
141+ PlatformDispatcher .instance._updateLifecycleState (state);
270142}
271143
272144@pragma ('vm:entry-point' )
273145// ignore: unused_element
274146void _updateSemanticsEnabled (bool enabled) {
275- final PlatformConfiguration previousConfiguration = PlatformDispatcher .instance.configuration;
276- if (previousConfiguration.semanticsEnabled == enabled) {
277- return ;
278- }
279- PlatformDispatcher .instance._configuration = previousConfiguration.copyWith (
280- semanticsEnabled: enabled,
281- );
282- _invoke (PlatformDispatcher .instance.onPlatformConfigurationChanged,
283- PlatformDispatcher .instance._onPlatformConfigurationChangedZone);
284- _invoke (PlatformDispatcher .instance.onSemanticsEnabledChanged,
285- PlatformDispatcher .instance._onSemanticsEnabledChangedZone);
147+ PlatformDispatcher .instance._updateSemanticsEnabled (enabled);
286148}
287149
288150@pragma ('vm:entry-point' )
289151// ignore: unused_element
290152void _updateAccessibilityFeatures (int values) {
291153 final AccessibilityFeatures newFeatures = AccessibilityFeatures ._(values);
292- final PlatformConfiguration previousConfiguration = PlatformDispatcher .instance.configuration;
293- if (newFeatures == previousConfiguration.accessibilityFeatures) {
294- return ;
295- }
296- PlatformDispatcher .instance._configuration = previousConfiguration.copyWith (
297- accessibilityFeatures: newFeatures,
298- );
299- _invoke (
300- PlatformDispatcher .instance.onPlatformConfigurationChanged,
301- PlatformDispatcher .instance._onPlatformConfigurationChangedZone,
302- );
303- _invoke (
304- PlatformDispatcher .instance.onAccessibilityFeaturesChanged,
305- PlatformDispatcher .instance._onAccessibilityFeaturesChangedZone,
306- );
154+ PlatformDispatcher .instance._updateAccessibilityFeatures (newFeatures);
307155}
308156
309157@pragma ('vm:entry-point' )
310158// ignore: unused_element
311159void _dispatchPlatformMessage (String name, ByteData ? data, int responseId) {
312- if (name == ChannelBuffers .kControlChannelName) {
313- try {
314- channelBuffers.handleMessage (data! );
315- } catch (ex) {
316- _printDebug ('Message to "$name " caused exception $ex ' );
317- } finally {
318- PlatformDispatcher .instance._respondToPlatformMessage (responseId, null );
319- }
320- } else if (PlatformDispatcher .instance.onPlatformMessage != null ) {
321- _invoke3 <String , ByteData ?, PlatformMessageResponseCallback >(
322- PlatformDispatcher .instance.onPlatformMessage,
323- PlatformDispatcher .instance._onPlatformMessageZone,
324- name,
325- data,
326- (ByteData ? responseData) {
327- PlatformDispatcher .instance._respondToPlatformMessage (responseId, responseData);
328- },
329- );
330- } else {
331- channelBuffers.push (name, data, (ByteData ? responseData) {
332- PlatformDispatcher .instance._respondToPlatformMessage (responseId, responseData);
333- });
334- }
160+ PlatformDispatcher .instance._dispatchPlatformMessage (name, data, responseId);
335161}
336162
337163@pragma ('vm:entry-point' )
@@ -455,8 +281,8 @@ void _invoke1<A>(void callback(A a)?, Zone zone, A arg) {
455281
456282/// Invokes [callback] inside the given [zone] passing it [arg1] , [arg2] , and [arg3] .
457283void _invoke3 <A1 , A2 , A3 >(
458- void callback (A1 a1, A2 a2, A3 a3) ? ,
459- Zone zone,
284+ void callback (A1 a1, A2 a2, A3 a3)? ,
285+ Zone zone,
460286 A1 arg1,
461287 A2 arg2,
462288 A3 arg3,
0 commit comments