1// Copyright 2013 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 5part of dart.ui; 6 7/// Signature of callbacks that have no arguments and return no data. 8typedef VoidCallback = void Function(); 9 10/// Signature for [Window.onBeginFrame]. 11typedef FrameCallback = void Function(Duration duration); 12 13/// Signature for [Window.onReportTimings]. 14/// 15/// {@template dart.ui.TimingsCallback.list} 16/// The callback takes a list of [FrameTiming] because it may not be 17/// immediately triggered after each frame. Instead, Flutter tries to batch 18/// frames together and send all their timings at once to decrease the 19/// overhead (as this is available in the release mode). The list is sorted in 20/// ascending order of time (earliest frame first). The timing of any frame 21/// will be sent within about 1 second (100ms if in the profile/debug mode) 22/// even if there are no later frames to batch. The timing of the first frame 23/// will be sent immediately without batching. 24/// {@endtemplate} 25typedef TimingsCallback = void Function(List<FrameTiming> timings); 26 27/// Signature for [Window.onPointerDataPacket]. 28typedef PointerDataPacketCallback = void Function(PointerDataPacket packet); 29 30/// Signature for [Window.onSemanticsAction]. 31typedef SemanticsActionCallback = void Function(int id, SemanticsAction action, ByteData args); 32 33/// Signature for responses to platform messages. 34/// 35/// Used as a parameter to [Window.sendPlatformMessage] and 36/// [Window.onPlatformMessage]. 37typedef PlatformMessageResponseCallback = void Function(ByteData data); 38 39/// Signature for [Window.onPlatformMessage]. 40typedef PlatformMessageCallback = void Function(String name, ByteData data, PlatformMessageResponseCallback callback); 41 42// Signature for _setNeedsReportTimings. 43typedef _SetNeedsReportTimingsFunc = void Function(bool value); 44 45/// Various important time points in the lifetime of a frame. 46/// 47/// [FrameTiming] records a timestamp of each phase for performance analysis. 48enum FramePhase { 49 /// When the UI thread starts building a frame. 50 /// 51 /// See also [FrameTiming.buildDuration]. 52 buildStart, 53 54 /// When the UI thread finishes building a frame. 55 /// 56 /// See also [FrameTiming.buildDuration]. 57 buildFinish, 58 59 /// When the GPU thread starts rasterizing a frame. 60 /// 61 /// See also [FrameTiming.rasterDuration]. 62 rasterStart, 63 64 /// When the GPU thread finishes rasterizing a frame. 65 /// 66 /// See also [FrameTiming.rasterDuration]. 67 rasterFinish, 68} 69 70/// Time-related performance metrics of a frame. 71/// 72/// See [Window.onReportTimings] for how to get this. 73/// 74/// The metrics in debug mode (`flutter run` without any flags) may be very 75/// different from those in profile and release modes due to the debug overhead. 76/// Therefore it's recommended to only monitor and analyze performance metrics 77/// in profile and release modes. 78class FrameTiming { 79 /// Construct [FrameTiming] with raw timestamps in microseconds. 80 /// 81 /// List [timestamps] must have the same number of elements as 82 /// [FramePhase.values]. 83 /// 84 /// This constructor is usually only called by the Flutter engine, or a test. 85 /// To get the [FrameTiming] of your app, see [Window.onReportTimings]. 86 FrameTiming(List<int> timestamps) 87 : assert(timestamps.length == FramePhase.values.length), _timestamps = timestamps; 88 89 /// This is a raw timestamp in microseconds from some epoch. The epoch in all 90 /// [FrameTiming] is the same, but it may not match [DateTime]'s epoch. 91 int timestampInMicroseconds(FramePhase phase) => _timestamps[phase.index]; 92 93 Duration _rawDuration(FramePhase phase) => Duration(microseconds: _timestamps[phase.index]); 94 95 /// The duration to build the frame on the UI thread. 96 /// 97 /// The build starts approximately when [Window.onBeginFrame] is called. The 98 /// [Duration] in the [Window.onBeginFrame] callback is exactly the 99 /// `Duration(microseconds: timestampInMicroseconds(FramePhase.buildStart))`. 100 /// 101 /// The build finishes when [Window.render] is called. 102 /// 103 /// {@template dart.ui.FrameTiming.fps_smoothness_milliseconds} 104 /// To ensure smooth animations of X fps, this should not exceed 1000/X 105 /// milliseconds. 106 /// {@endtemplate} 107 /// {@template dart.ui.FrameTiming.fps_milliseconds} 108 /// That's about 16ms for 60fps, and 8ms for 120fps. 109 /// {@endtemplate} 110 Duration get buildDuration => _rawDuration(FramePhase.buildFinish) - _rawDuration(FramePhase.buildStart); 111 112 /// The duration to rasterize the frame on the GPU thread. 113 /// 114 /// {@macro dart.ui.FrameTiming.fps_smoothness_milliseconds} 115 /// {@macro dart.ui.FrameTiming.fps_milliseconds} 116 Duration get rasterDuration => _rawDuration(FramePhase.rasterFinish) - _rawDuration(FramePhase.rasterStart); 117 118 /// The timespan between build start and raster finish. 119 /// 120 /// To achieve the lowest latency on an X fps display, this should not exceed 121 /// 1000/X milliseconds. 122 /// {@macro dart.ui.FrameTiming.fps_milliseconds} 123 /// 124 /// See also [buildDuration] and [rasterDuration]. 125 Duration get totalSpan => _rawDuration(FramePhase.rasterFinish) - _rawDuration(FramePhase.buildStart); 126 127 final List<int> _timestamps; // in microseconds 128 129 String _formatMS(Duration duration) => '${duration.inMicroseconds * 0.001}ms'; 130 131 @override 132 String toString() { 133 return '$runtimeType(buildDuration: ${_formatMS(buildDuration)}, rasterDuration: ${_formatMS(rasterDuration)}, totalSpan: ${_formatMS(totalSpan)})'; 134 } 135} 136 137/// States that an application can be in. 138/// 139/// The values below describe notifications from the operating system. 140/// Applications should not expect to always receive all possible 141/// notifications. For example, if the users pulls out the battery from the 142/// device, no notification will be sent before the application is suddenly 143/// terminated, along with the rest of the operating system. 144/// 145/// See also: 146/// 147/// * [WidgetsBindingObserver], for a mechanism to observe the lifecycle state 148/// from the widgets layer. 149enum AppLifecycleState { 150 /// The application is visible and responding to user input. 151 resumed, 152 153 /// The application is in an inactive state and is not receiving user input. 154 /// 155 /// On iOS, this state corresponds to an app or the Flutter host view running 156 /// in the foreground inactive state. Apps transition to this state when in 157 /// a phone call, responding to a TouchID request, when entering the app 158 /// switcher or the control center, or when the UIViewController hosting the 159 /// Flutter app is transitioning. 160 /// 161 /// On Android, this corresponds to an app or the Flutter host view running 162 /// in the foreground inactive state. Apps transition to this state when 163 /// another activity is focused, such as a split-screen app, a phone call, 164 /// a picture-in-picture app, a system dialog, or another window. 165 /// 166 /// Apps in this state should assume that they may be [paused] at any time. 167 inactive, 168 169 /// The application is not currently visible to the user, not responding to 170 /// user input, and running in the background. 171 /// 172 /// When the application is in this state, the engine will not call the 173 /// [Window.onBeginFrame] and [Window.onDrawFrame] callbacks. 174 /// 175 /// Android apps in this state should assume that they may enter the 176 /// [suspending] state at any time. 177 paused, 178 179 /// The application will be suspended momentarily. 180 /// 181 /// When the application is in this state, the engine will not call the 182 /// [Window.onBeginFrame] and [Window.onDrawFrame] callbacks. 183 /// 184 /// On iOS, this state is currently unused. 185 suspending, 186} 187 188/// A representation of distances for each of the four edges of a rectangle, 189/// used to encode the view insets and padding that applications should place 190/// around their user interface, as exposed by [Window.viewInsets] and 191/// [Window.padding]. View insets and padding are preferably read via 192/// [MediaQuery.of]. 193/// 194/// For a generic class that represents distances around a rectangle, see the 195/// [EdgeInsets] class. 196/// 197/// See also: 198/// 199/// * [WidgetsBindingObserver], for a widgets layer mechanism to receive 200/// notifications when the padding changes. 201/// * [MediaQuery.of], for the preferred mechanism for accessing these values. 202/// * [Scaffold], which automatically applies the padding in material design 203/// applications. 204class WindowPadding { 205 const WindowPadding._({ this.left, this.top, this.right, this.bottom }); 206 207 /// The distance from the left edge to the first unpadded pixel, in physical pixels. 208 final double left; 209 210 /// The distance from the top edge to the first unpadded pixel, in physical pixels. 211 final double top; 212 213 /// The distance from the right edge to the first unpadded pixel, in physical pixels. 214 final double right; 215 216 /// The distance from the bottom edge to the first unpadded pixel, in physical pixels. 217 final double bottom; 218 219 /// A window padding that has zeros for each edge. 220 static const WindowPadding zero = WindowPadding._(left: 0.0, top: 0.0, right: 0.0, bottom: 0.0); 221 222 @override 223 String toString() { 224 return 'WindowPadding(left: $left, top: $top, right: $right, bottom: $bottom)'; 225 } 226} 227 228/// An identifier used to select a user's language and formatting preferences. 229/// 230/// This represents a [Unicode Language 231/// Identifier](https://www.unicode.org/reports/tr35/#Unicode_language_identifier) 232/// (i.e. without Locale extensions), except variants are not supported. 233/// 234/// Locales are canonicalized according to the "preferred value" entries in the 235/// [IANA Language Subtag 236/// Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry). 237/// For example, `const Locale('he')` and `const Locale('iw')` are equal and 238/// both have the [languageCode] `he`, because `iw` is a deprecated language 239/// subtag that was replaced by the subtag `he`. 240/// 241/// See also: 242/// 243/// * [Window.locale], which specifies the system's currently selected 244/// [Locale]. 245class Locale { 246 /// Creates a new Locale object. The first argument is the 247 /// primary language subtag, the second is the region (also 248 /// referred to as 'country') subtag. 249 /// 250 /// For example: 251 /// 252 /// ```dart 253 /// const Locale swissFrench = Locale('fr', 'CH'); 254 /// const Locale canadianFrench = Locale('fr', 'CA'); 255 /// ``` 256 /// 257 /// The primary language subtag must not be null. The region subtag is 258 /// optional. When there is no region/country subtag, the parameter should 259 /// be omitted or passed `null` instead of an empty-string. 260 /// 261 /// The subtag values are _case sensitive_ and must be one of the valid 262 /// subtags according to CLDR supplemental data: 263 /// [language](http://unicode.org/cldr/latest/common/validity/language.xml), 264 /// [region](http://unicode.org/cldr/latest/common/validity/region.xml). The 265 /// primary language subtag must be at least two and at most eight lowercase 266 /// letters, but not four letters. The region region subtag must be two 267 /// uppercase letters or three digits. See the [Unicode Language 268 /// Identifier](https://www.unicode.org/reports/tr35/#Unicode_language_identifier) 269 /// specification. 270 /// 271 /// Validity is not checked by default, but some methods may throw away 272 /// invalid data. 273 /// 274 /// See also: 275 /// 276 /// * [Locale.fromSubtags], which also allows a [scriptCode] to be 277 /// specified. 278 const Locale( 279 this._languageCode, [ 280 this._countryCode, 281 ]) : assert(_languageCode != null), 282 assert(_languageCode != ''), 283 scriptCode = null; 284 285 /// Creates a new Locale object. 286 /// 287 /// The keyword arguments specify the subtags of the Locale. 288 /// 289 /// The subtag values are _case sensitive_ and must be valid subtags according 290 /// to CLDR supplemental data: 291 /// [language](http://unicode.org/cldr/latest/common/validity/language.xml), 292 /// [script](http://unicode.org/cldr/latest/common/validity/script.xml) and 293 /// [region](http://unicode.org/cldr/latest/common/validity/region.xml) for 294 /// each of languageCode, scriptCode and countryCode respectively. 295 /// 296 /// The [countryCode] subtag is optional. When there is no country subtag, 297 /// the parameter should be omitted or passed `null` instead of an empty-string. 298 /// 299 /// Validity is not checked by default, but some methods may throw away 300 /// invalid data. 301 const Locale.fromSubtags({ 302 String languageCode = 'und', 303 this.scriptCode, 304 String countryCode, 305 }) : assert(languageCode != null), 306 assert(languageCode != ''), 307 _languageCode = languageCode, 308 assert(scriptCode != ''), 309 assert(countryCode != ''), 310 _countryCode = countryCode; 311 312 /// The primary language subtag for the locale. 313 /// 314 /// This must not be null. It may be 'und', representing 'undefined'. 315 /// 316 /// This is expected to be string registered in the [IANA Language Subtag 317 /// Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry) 318 /// with the type "language". The string specified must match the case of the 319 /// string in the registry. 320 /// 321 /// Language subtags that are deprecated in the registry and have a preferred 322 /// code are changed to their preferred code. For example, `const 323 /// Locale('he')` and `const Locale('iw')` are equal, and both have the 324 /// [languageCode] `he`, because `iw` is a deprecated language subtag that was 325 /// replaced by the subtag `he`. 326 /// 327 /// This must be a valid Unicode Language subtag as listed in [Unicode CLDR 328 /// supplemental 329 /// data](http://unicode.org/cldr/latest/common/validity/language.xml). 330 /// 331 /// See also: 332 /// 333 /// * [Locale.fromSubtags], which describes the conventions for creating 334 /// [Locale] objects. 335 String get languageCode => _deprecatedLanguageSubtagMap[_languageCode] ?? _languageCode; 336 final String _languageCode; 337 338 // This map is generated by //flutter/tools/gen_locale.dart 339 // Mappings generated for language subtag registry as of 2019-02-27. 340 static const Map<String, String> _deprecatedLanguageSubtagMap = <String, String>{ 341 'in': 'id', // Indonesian; deprecated 1989-01-01 342 'iw': 'he', // Hebrew; deprecated 1989-01-01 343 'ji': 'yi', // Yiddish; deprecated 1989-01-01 344 'jw': 'jv', // Javanese; deprecated 2001-08-13 345 'mo': 'ro', // Moldavian, Moldovan; deprecated 2008-11-22 346 'aam': 'aas', // Aramanik; deprecated 2015-02-12 347 'adp': 'dz', // Adap; deprecated 2015-02-12 348 'aue': 'ktz', // ǂKxʼauǁʼein; deprecated 2015-02-12 349 'ayx': 'nun', // Ayi (China); deprecated 2011-08-16 350 'bgm': 'bcg', // Baga Mboteni; deprecated 2016-05-30 351 'bjd': 'drl', // Bandjigali; deprecated 2012-08-12 352 'ccq': 'rki', // Chaungtha; deprecated 2012-08-12 353 'cjr': 'mom', // Chorotega; deprecated 2010-03-11 354 'cka': 'cmr', // Khumi Awa Chin; deprecated 2012-08-12 355 'cmk': 'xch', // Chimakum; deprecated 2010-03-11 356 'coy': 'pij', // Coyaima; deprecated 2016-05-30 357 'cqu': 'quh', // Chilean Quechua; deprecated 2016-05-30 358 'drh': 'khk', // Darkhat; deprecated 2010-03-11 359 'drw': 'prs', // Darwazi; deprecated 2010-03-11 360 'gav': 'dev', // Gabutamon; deprecated 2010-03-11 361 'gfx': 'vaj', // Mangetti Dune ǃXung; deprecated 2015-02-12 362 'ggn': 'gvr', // Eastern Gurung; deprecated 2016-05-30 363 'gti': 'nyc', // Gbati-ri; deprecated 2015-02-12 364 'guv': 'duz', // Gey; deprecated 2016-05-30 365 'hrr': 'jal', // Horuru; deprecated 2012-08-12 366 'ibi': 'opa', // Ibilo; deprecated 2012-08-12 367 'ilw': 'gal', // Talur; deprecated 2013-09-10 368 'jeg': 'oyb', // Jeng; deprecated 2017-02-23 369 'kgc': 'tdf', // Kasseng; deprecated 2016-05-30 370 'kgh': 'kml', // Upper Tanudan Kalinga; deprecated 2012-08-12 371 'koj': 'kwv', // Sara Dunjo; deprecated 2015-02-12 372 'krm': 'bmf', // Krim; deprecated 2017-02-23 373 'ktr': 'dtp', // Kota Marudu Tinagas; deprecated 2016-05-30 374 'kvs': 'gdj', // Kunggara; deprecated 2016-05-30 375 'kwq': 'yam', // Kwak; deprecated 2015-02-12 376 'kxe': 'tvd', // Kakihum; deprecated 2015-02-12 377 'kzj': 'dtp', // Coastal Kadazan; deprecated 2016-05-30 378 'kzt': 'dtp', // Tambunan Dusun; deprecated 2016-05-30 379 'lii': 'raq', // Lingkhim; deprecated 2015-02-12 380 'lmm': 'rmx', // Lamam; deprecated 2014-02-28 381 'meg': 'cir', // Mea; deprecated 2013-09-10 382 'mst': 'mry', // Cataelano Mandaya; deprecated 2010-03-11 383 'mwj': 'vaj', // Maligo; deprecated 2015-02-12 384 'myt': 'mry', // Sangab Mandaya; deprecated 2010-03-11 385 'nad': 'xny', // Nijadali; deprecated 2016-05-30 386 'ncp': 'kdz', // Ndaktup; deprecated 2018-03-08 387 'nnx': 'ngv', // Ngong; deprecated 2015-02-12 388 'nts': 'pij', // Natagaimas; deprecated 2016-05-30 389 'oun': 'vaj', // ǃOǃung; deprecated 2015-02-12 390 'pcr': 'adx', // Panang; deprecated 2013-09-10 391 'pmc': 'huw', // Palumata; deprecated 2016-05-30 392 'pmu': 'phr', // Mirpur Panjabi; deprecated 2015-02-12 393 'ppa': 'bfy', // Pao; deprecated 2016-05-30 394 'ppr': 'lcq', // Piru; deprecated 2013-09-10 395 'pry': 'prt', // Pray 3; deprecated 2016-05-30 396 'puz': 'pub', // Purum Naga; deprecated 2014-02-28 397 'sca': 'hle', // Sansu; deprecated 2012-08-12 398 'skk': 'oyb', // Sok; deprecated 2017-02-23 399 'tdu': 'dtp', // Tempasuk Dusun; deprecated 2016-05-30 400 'thc': 'tpo', // Tai Hang Tong; deprecated 2016-05-30 401 'thx': 'oyb', // The; deprecated 2015-02-12 402 'tie': 'ras', // Tingal; deprecated 2011-08-16 403 'tkk': 'twm', // Takpa; deprecated 2011-08-16 404 'tlw': 'weo', // South Wemale; deprecated 2012-08-12 405 'tmp': 'tyj', // Tai Mène; deprecated 2016-05-30 406 'tne': 'kak', // Tinoc Kallahan; deprecated 2016-05-30 407 'tnf': 'prs', // Tangshewi; deprecated 2010-03-11 408 'tsf': 'taj', // Southwestern Tamang; deprecated 2015-02-12 409 'uok': 'ema', // Uokha; deprecated 2015-02-12 410 'xba': 'cax', // Kamba (Brazil); deprecated 2016-05-30 411 'xia': 'acn', // Xiandao; deprecated 2013-09-10 412 'xkh': 'waw', // Karahawyana; deprecated 2016-05-30 413 'xsj': 'suj', // Subi; deprecated 2015-02-12 414 'ybd': 'rki', // Yangbye; deprecated 2012-08-12 415 'yma': 'lrr', // Yamphe; deprecated 2012-08-12 416 'ymt': 'mtm', // Mator-Taygi-Karagas; deprecated 2015-02-12 417 'yos': 'zom', // Yos; deprecated 2013-09-10 418 'yuu': 'yug', // Yugh; deprecated 2014-02-28 419 }; 420 421 /// The script subtag for the locale. 422 /// 423 /// This may be null, indicating that there is no specified script subtag. 424 /// 425 /// This must be a valid Unicode Language Identifier script subtag as listed 426 /// in [Unicode CLDR supplemental 427 /// data](http://unicode.org/cldr/latest/common/validity/script.xml). 428 /// 429 /// See also: 430 /// 431 /// * [Locale.fromSubtags], which describes the conventions for creating 432 /// [Locale] objects. 433 final String scriptCode; 434 435 /// The region subtag for the locale. 436 /// 437 /// This may be null, indicating that there is no specified region subtag. 438 /// 439 /// This is expected to be string registered in the [IANA Language Subtag 440 /// Registry](https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry) 441 /// with the type "region". The string specified must match the case of the 442 /// string in the registry. 443 /// 444 /// Region subtags that are deprecated in the registry and have a preferred 445 /// code are changed to their preferred code. For example, `const Locale('de', 446 /// 'DE')` and `const Locale('de', 'DD')` are equal, and both have the 447 /// [countryCode] `DE`, because `DD` is a deprecated language subtag that was 448 /// replaced by the subtag `DE`. 449 /// 450 /// See also: 451 /// 452 /// * [Locale.fromSubtags], which describes the conventions for creating 453 /// [Locale] objects. 454 String get countryCode => _deprecatedRegionSubtagMap[_countryCode] ?? _countryCode; 455 final String _countryCode; 456 457 // This map is generated by //flutter/tools/gen_locale.dart 458 // Mappings generated for language subtag registry as of 2019-02-27. 459 static const Map<String, String> _deprecatedRegionSubtagMap = <String, String>{ 460 'BU': 'MM', // Burma; deprecated 1989-12-05 461 'DD': 'DE', // German Democratic Republic; deprecated 1990-10-30 462 'FX': 'FR', // Metropolitan France; deprecated 1997-07-14 463 'TP': 'TL', // East Timor; deprecated 2002-05-20 464 'YD': 'YE', // Democratic Yemen; deprecated 1990-08-14 465 'ZR': 'CD', // Zaire; deprecated 1997-07-14 466 }; 467 468 @override 469 bool operator ==(dynamic other) { 470 if (identical(this, other)) 471 return true; 472 if (other is! Locale) 473 return false; 474 final Locale typedOther = other; 475 return languageCode == typedOther.languageCode 476 && scriptCode == typedOther.scriptCode 477 && countryCode == typedOther.countryCode; 478 } 479 480 @override 481 int get hashCode => hashValues(languageCode, scriptCode, countryCode); 482 483 static Locale cachedLocale; 484 static String cachedLocaleString; 485 486 /// Returns a string representing the locale. 487 /// 488 /// This identifier happens to be a valid Unicode Locale Identifier using 489 /// underscores as separator, however it is intended to be used for debugging 490 /// purposes only. For parseable results, use [toLanguageTag] instead. 491 @override 492 String toString() { 493 if (!identical(cachedLocale, this)) { 494 cachedLocale = this; 495 cachedLocaleString = _rawToString('_'); 496 } 497 return cachedLocaleString; 498 } 499 500 /// Returns a syntactically valid Unicode BCP47 Locale Identifier. 501 /// 502 /// Some examples of such identifiers: "en", "es-419", "hi-Deva-IN" and 503 /// "zh-Hans-CN". See http://www.unicode.org/reports/tr35/ for technical 504 /// details. 505 String toLanguageTag() => _rawToString('-'); 506 507 String _rawToString(String separator) { 508 final StringBuffer out = StringBuffer(languageCode); 509 if (scriptCode != null) 510 out.write('$separator$scriptCode'); 511 if (_countryCode != null) 512 out.write('$separator$countryCode'); 513 return out.toString(); 514 } 515} 516 517/// The most basic interface to the host operating system's user interface. 518/// 519/// It exposes the size of the display, the core scheduler API, the input event 520/// callback, the graphics drawing API, and other such core services. 521/// 522/// There is a single Window instance in the system, which you can 523/// obtain from `WidgetsBinding.instance.window`. 524/// 525/// There is also a [window] singleton object in `dart:ui` if `WidgetsBinding` 526/// is unavailable. But we strongly advise to avoid statically referencing it. 527/// See the document of [window] for more details of why it should be avoided. 528/// 529/// ## Insets and Padding 530/// 531/// {@animation 300 300 https://flutter.github.io/assets-for-api-docs/assets/widgets/window_padding.mp4} 532/// 533/// In this diagram, the black areas represent system UI that the app cannot 534/// draw over. The red area represents view padding that the application may not 535/// be able to detect gestures in and may not want to draw in. The grey area 536/// represents the system keyboard, which can cover over the bottom view 537/// padding when visible. 538/// 539/// The [Window.viewInsets] are the physical pixels which the operating 540/// system reserves for system UI, such as the keyboard, which would fully 541/// obscure any content drawn in that area. 542/// 543/// The [Window.viewPadding] are the physical pixels on each side of the display 544/// that may be partially obscured by system UI or by physical intrusions into 545/// the display, such as an overscan region on a television or a "notch" on a 546/// phone. Unlike the insets, these areas may have portions that show the user 547/// application painted pixels without being obscured, such as a notch at the 548/// top of a phone that covers only a subset of the area. Insets, on the other 549/// hand, either partially or fully obscure the window, such as an opaque 550/// keyboard or a partially transluscent statusbar, which cover an area without 551/// gaps. 552/// 553/// The [Window.padding] property is computed from both [Window.viewInsets] and 554/// [Window.viewPadding]. It will allow a view inset to consume view padding 555/// where appropriate, such as when a phone's keyboard is covering the bottom 556/// view padding and so "absorbs" it. 557/// 558/// Clients that want to position elements relative to the view padding 559/// regardless of the view insets should use the [Window.viewPadding] property, 560/// e.g. if you wish to draw a widget at the center of the screen with respect 561/// to the iPhone "safe area" regardless of whether the keyboard is showing. 562/// 563/// [Window.padding] is useful for clients that want to know how much padding 564/// should be accounted for without concern for the current inset(s) state, e.g. 565/// determining whether a gesture should be considered for scrolling purposes. 566/// This value varies based on the current state of the insets. For example, a 567/// visible keyboard will consume all gestures in the bottom part of the 568/// [Window.viewPadding] anyway, so there is no need to account for that in the 569/// [Window.padding], which is always safe to use for such calculations. 570class Window { 571 Window._() { 572 _setNeedsReportTimings = _nativeSetNeedsReportTimings; 573 } 574 575 /// The number of device pixels for each logical pixel. This number might not 576 /// be a power of two. Indeed, it might not even be an integer. For example, 577 /// the Nexus 6 has a device pixel ratio of 3.5. 578 /// 579 /// Device pixels are also referred to as physical pixels. Logical pixels are 580 /// also referred to as device-independent or resolution-independent pixels. 581 /// 582 /// By definition, there are roughly 38 logical pixels per centimeter, or 583 /// about 96 logical pixels per inch, of the physical display. The value 584 /// returned by [devicePixelRatio] is ultimately obtained either from the 585 /// hardware itself, the device drivers, or a hard-coded value stored in the 586 /// operating system or firmware, and may be inaccurate, sometimes by a 587 /// significant margin. 588 /// 589 /// The Flutter framework operates in logical pixels, so it is rarely 590 /// necessary to directly deal with this property. 591 /// 592 /// When this changes, [onMetricsChanged] is called. 593 /// 594 /// See also: 595 /// 596 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 597 /// observe when this value changes. 598 double get devicePixelRatio => _devicePixelRatio; 599 double _devicePixelRatio = 1.0; 600 601 /// The dimensions of the rectangle into which the application will be drawn, 602 /// in physical pixels. 603 /// 604 /// When this changes, [onMetricsChanged] is called. 605 /// 606 /// At startup, the size of the application window may not be known before Dart 607 /// code runs. If this value is observed early in the application lifecycle, 608 /// it may report [Size.zero]. 609 /// 610 /// This value does not take into account any on-screen keyboards or other 611 /// system UI. The [padding] and [viewInsets] properties provide a view into 612 /// how much of each side of the application may be obscured by system UI. 613 /// 614 /// See also: 615 /// 616 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 617 /// observe when this value changes. 618 Size get physicalSize => _physicalSize; 619 Size _physicalSize = Size.zero; 620 621 /// The physical depth is the maximum elevation that the Window allows. 622 /// 623 /// Physical layers drawn at or above this elevation will have their elevation 624 /// clamped to this value. This can happen if the physical layer itself has 625 /// an elevation larger than available depth, or if some ancestor of the layer 626 /// causes it to have a cumulative elevation that is larger than the available 627 /// depth. 628 /// 629 /// The default value is [double.maxFinite], which is used for platforms that 630 /// do not specify a maximum elevation. This property is currently on expected 631 /// to be set to a non-default value on Fuchsia. 632 double get physicalDepth => _physicalDepth; 633 double _physicalDepth = double.maxFinite; 634 635 /// The number of physical pixels on each side of the display rectangle into 636 /// which the application can render, but over which the operating system 637 /// will likely place system UI, such as the keyboard, that fully obscures 638 /// any content. 639 /// 640 /// When this property changes, [onMetricsChanged] is called. 641 /// 642 /// The relationship between this [Window.viewInsets], [Window.viewPadding], 643 /// and [Window.padding] are described in more detail in the documentation for 644 /// [Window]. 645 /// 646 /// See also: 647 /// 648 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 649 /// observe when this value changes. 650 /// * [MediaQuery.of], a simpler mechanism for the same. 651 /// * [Scaffold], which automatically applies the view insets in material 652 /// design applications. 653 WindowPadding get viewInsets => _viewInsets; 654 WindowPadding _viewInsets = WindowPadding.zero; 655 656 /// The number of physical pixels on each side of the display rectangle into 657 /// which the application can render, but which may be partially obscured by 658 /// system UI (such as the system notification area), or or physical 659 /// intrusions in the display (e.g. overscan regions on television screens or 660 /// phone sensor housings). 661 /// 662 /// Unlike [Window.padding], this value does not change relative to 663 /// [Window.viewInsets]. For example, on an iPhone X, it will not change in 664 /// response to the soft keyboard being visible or hidden, whereas 665 /// [Window.padding] will. 666 /// 667 /// When this property changes, [onMetricsChanged] is called. 668 /// 669 /// The relationship between this [Window.viewInsets], [Window.viewPadding], 670 /// and [Window.padding] are described in more detail in the documentation for 671 /// [Window]. 672 /// 673 /// See also: 674 /// 675 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 676 /// observe when this value changes. 677 /// * [MediaQuery.of], a simpler mechanism for the same. 678 /// * [Scaffold], which automatically applies the padding in material design 679 /// applications. 680 WindowPadding get viewPadding => _viewPadding; 681 WindowPadding _viewPadding = WindowPadding.zero; 682 683 /// The number of physical pixels on each side of the display rectangle into 684 /// which the application can render, but where the operating system will 685 /// consume input gestures for the sake of system navigation. 686 /// 687 /// For example, an operating system might use the vertical edges of the 688 /// screen, where swiping inwards from the edges takes users backward 689 /// through the history of screens they previously visited. 690 /// 691 /// When this property changes, [onMetricsChanged] is called. 692 /// 693 /// See also: 694 /// 695 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 696 /// observe when this value changes. 697 /// * [MediaQuery.of], a simpler mechanism for the same. 698 WindowPadding get systemGestureInsets => _systemGestureInsets; 699 WindowPadding _systemGestureInsets = WindowPadding.zero; 700 701 /// The number of physical pixels on each side of the display rectangle into 702 /// which the application can render, but which may be partially obscured by 703 /// system UI (such as the system notification area), or or physical 704 /// intrusions in the display (e.g. overscan regions on television screens or 705 /// phone sensor housings). 706 /// 707 /// This value is calculated by taking 708 /// `max(0.0, Window.viewPadding - Window.viewInsets)`. This will treat a 709 /// system IME that increases the bottom inset as consuming that much of the 710 /// bottom padding. For example, on an iPhone X, [Window.padding.bottom] is 711 /// the same as [Window.viewPadding.bottom] when the soft keyboard is not 712 /// drawn (to account for the bottom soft button area), but will be `0.0` when 713 /// the soft keyboard is visible. 714 /// 715 /// When this changes, [onMetricsChanged] is called. 716 /// 717 /// The relationship between this [Window.viewInsets], [Window.viewPadding], 718 /// and [Window.padding] are described in more detail in the documentation for 719 /// [Window]. 720 /// 721 /// See also: 722 /// 723 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 724 /// observe when this value changes. 725 /// * [MediaQuery.of], a simpler mechanism for the same. 726 /// * [Scaffold], which automatically applies the padding in material design 727 /// applications. 728 WindowPadding get padding => _padding; 729 WindowPadding _padding = WindowPadding.zero; 730 731 /// A callback that is invoked whenever the [devicePixelRatio], 732 /// [physicalSize], [padding], [viewInsets], or [systemGestureInsets] 733 /// values change, for example when the device is rotated or when the 734 /// application is resized (e.g. when showing applications side-by-side 735 /// on Android). 736 /// 737 /// The engine invokes this callback in the same zone in which the callback 738 /// was set. 739 /// 740 /// The framework registers with this callback and updates the layout 741 /// appropriately. 742 /// 743 /// See also: 744 /// 745 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 746 /// register for notifications when this is called. 747 /// * [MediaQuery.of], a simpler mechanism for the same. 748 VoidCallback get onMetricsChanged => _onMetricsChanged; 749 VoidCallback _onMetricsChanged; 750 Zone _onMetricsChangedZone; 751 set onMetricsChanged(VoidCallback callback) { 752 _onMetricsChanged = callback; 753 _onMetricsChangedZone = Zone.current; 754 } 755 756 /// The system-reported default locale of the device. 757 /// 758 /// This establishes the language and formatting conventions that application 759 /// should, if possible, use to render their user interface. 760 /// 761 /// This is the first locale selected by the user and is the user's 762 /// primary locale (the locale the device UI is displayed in) 763 /// 764 /// This is equivalent to `locales.first` and will provide an empty non-null locale 765 /// if the [locales] list has not been set or is empty. 766 Locale get locale { 767 if (_locales != null && _locales.isNotEmpty) { 768 return _locales.first; 769 } 770 return null; 771 } 772 773 /// The full system-reported supported locales of the device. 774 /// 775 /// This establishes the language and formatting conventions that application 776 /// should, if possible, use to render their user interface. 777 /// 778 /// The list is ordered in order of priority, with lower-indexed locales being 779 /// preferred over higher-indexed ones. The first element is the primary [locale]. 780 /// 781 /// The [onLocaleChanged] callback is called whenever this value changes. 782 /// 783 /// See also: 784 /// 785 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 786 /// observe when this value changes. 787 List<Locale> get locales => _locales; 788 List<Locale> _locales; 789 790 /// A callback that is invoked whenever [locale] changes value. 791 /// 792 /// The framework invokes this callback in the same zone in which the 793 /// callback was set. 794 /// 795 /// See also: 796 /// 797 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 798 /// observe when this callback is invoked. 799 VoidCallback get onLocaleChanged => _onLocaleChanged; 800 VoidCallback _onLocaleChanged; 801 Zone _onLocaleChangedZone; 802 set onLocaleChanged(VoidCallback callback) { 803 _onLocaleChanged = callback; 804 _onLocaleChangedZone = Zone.current; 805 } 806 807 /// The lifecycle state immediately after dart isolate initialization. 808 /// 809 /// This property will not be updated as the lifecycle changes. 810 /// 811 /// It is used to initialize [SchedulerBinding.lifecycleState] at startup 812 /// with any buffered lifecycle state events. 813 String get initialLifecycleState { 814 _initialLifecycleStateAccessed = true; 815 return _initialLifecycleState; 816 } 817 String _initialLifecycleState; 818 /// Tracks if the initial state has been accessed. Once accessed, we 819 /// will stop updating the [initialLifecycleState], as it is not the 820 /// preferred way to access the state. 821 bool _initialLifecycleStateAccessed = false; 822 823 /// The system-reported text scale. 824 /// 825 /// This establishes the text scaling factor to use when rendering text, 826 /// according to the user's platform preferences. 827 /// 828 /// The [onTextScaleFactorChanged] callback is called whenever this value 829 /// changes. 830 /// 831 /// See also: 832 /// 833 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 834 /// observe when this value changes. 835 double get textScaleFactor => _textScaleFactor; 836 double _textScaleFactor = 1.0; 837 838 /// The setting indicating whether time should always be shown in the 24-hour 839 /// format. 840 /// 841 /// This option is used by [showTimePicker]. 842 bool get alwaysUse24HourFormat => _alwaysUse24HourFormat; 843 bool _alwaysUse24HourFormat = false; 844 845 /// A callback that is invoked whenever [textScaleFactor] changes value. 846 /// 847 /// The framework invokes this callback in the same zone in which the 848 /// callback was set. 849 /// 850 /// See also: 851 /// 852 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 853 /// observe when this callback is invoked. 854 VoidCallback get onTextScaleFactorChanged => _onTextScaleFactorChanged; 855 VoidCallback _onTextScaleFactorChanged; 856 Zone _onTextScaleFactorChangedZone; 857 set onTextScaleFactorChanged(VoidCallback callback) { 858 _onTextScaleFactorChanged = callback; 859 _onTextScaleFactorChangedZone = Zone.current; 860 } 861 862 /// The setting indicating the current brightness mode of the host platform. 863 /// If the platform has no preference, [platformBrightness] defaults to [Brightness.light]. 864 Brightness get platformBrightness => _platformBrightness; 865 Brightness _platformBrightness = Brightness.light; 866 867 /// A callback that is invoked whenever [platformBrightness] changes value. 868 /// 869 /// The framework invokes this callback in the same zone in which the 870 /// callback was set. 871 /// 872 /// See also: 873 /// 874 /// * [WidgetsBindingObserver], for a mechanism at the widgets layer to 875 /// observe when this callback is invoked. 876 VoidCallback get onPlatformBrightnessChanged => _onPlatformBrightnessChanged; 877 VoidCallback _onPlatformBrightnessChanged; 878 Zone _onPlatformBrightnessChangedZone; 879 set onPlatformBrightnessChanged(VoidCallback callback) { 880 _onPlatformBrightnessChanged = callback; 881 _onPlatformBrightnessChangedZone = Zone.current; 882 } 883 884 /// A callback that is invoked to notify the application that it is an 885 /// appropriate time to provide a scene using the [SceneBuilder] API and the 886 /// [render] method. When possible, this is driven by the hardware VSync 887 /// signal. This is only called if [scheduleFrame] has been called since the 888 /// last time this callback was invoked. 889 /// 890 /// The [onDrawFrame] callback is invoked immediately after [onBeginFrame], 891 /// after draining any microtasks (e.g. completions of any [Future]s) queued 892 /// by the [onBeginFrame] handler. 893 /// 894 /// The framework invokes this callback in the same zone in which the 895 /// callback was set. 896 /// 897 /// See also: 898 /// 899 /// * [SchedulerBinding], the Flutter framework class which manages the 900 /// scheduling of frames. 901 /// * [RendererBinding], the Flutter framework class which manages layout and 902 /// painting. 903 FrameCallback get onBeginFrame => _onBeginFrame; 904 FrameCallback _onBeginFrame; 905 Zone _onBeginFrameZone; 906 set onBeginFrame(FrameCallback callback) { 907 _onBeginFrame = callback; 908 _onBeginFrameZone = Zone.current; 909 } 910 911 /// A callback that is invoked for each frame after [onBeginFrame] has 912 /// completed and after the microtask queue has been drained. This can be 913 /// used to implement a second phase of frame rendering that happens 914 /// after any deferred work queued by the [onBeginFrame] phase. 915 /// 916 /// The framework invokes this callback in the same zone in which the 917 /// callback was set. 918 /// 919 /// See also: 920 /// 921 /// * [SchedulerBinding], the Flutter framework class which manages the 922 /// scheduling of frames. 923 /// * [RendererBinding], the Flutter framework class which manages layout and 924 /// painting. 925 VoidCallback get onDrawFrame => _onDrawFrame; 926 VoidCallback _onDrawFrame; 927 Zone _onDrawFrameZone; 928 set onDrawFrame(VoidCallback callback) { 929 _onDrawFrame = callback; 930 _onDrawFrameZone = Zone.current; 931 } 932 933 /// A callback that is invoked to report the [FrameTiming] of recently 934 /// rasterized frames. 935 /// 936 /// This can be used to see if the application has missed frames (through 937 /// [FrameTiming.buildDuration] and [FrameTiming.rasterDuration]), or high 938 /// latencies (through [FrameTiming.totalSpan]). 939 /// 940 /// Unlike [Timeline], the timing information here is available in the release 941 /// mode (additional to the profile and the debug mode). Hence this can be 942 /// used to monitor the application's performance in the wild. 943 /// 944 /// {@macro dart.ui.TimingsCallback.list} 945 /// 946 /// If this is null, no additional work will be done. If this is not null, 947 /// Flutter spends less than 0.1ms every 1 second to report the timings 948 /// (measured on iPhone6S). The 0.1ms is about 0.6% of 16ms (frame budget for 949 /// 60fps), or 0.01% CPU usage per second. 950 TimingsCallback get onReportTimings => _onReportTimings; 951 TimingsCallback _onReportTimings; 952 Zone _onReportTimingsZone; 953 set onReportTimings(TimingsCallback callback) { 954 if ((callback == null) != (_onReportTimings == null)) { 955 _setNeedsReportTimings(callback != null); 956 } 957 _onReportTimings = callback; 958 _onReportTimingsZone = Zone.current; 959 } 960 961 _SetNeedsReportTimingsFunc _setNeedsReportTimings; 962 void _nativeSetNeedsReportTimings(bool value) native 'Window_setNeedsReportTimings'; 963 964 /// A callback that is invoked when pointer data is available. 965 /// 966 /// The framework invokes this callback in the same zone in which the 967 /// callback was set. 968 /// 969 /// See also: 970 /// 971 /// * [GestureBinding], the Flutter framework class which manages pointer 972 /// events. 973 PointerDataPacketCallback get onPointerDataPacket => _onPointerDataPacket; 974 PointerDataPacketCallback _onPointerDataPacket; 975 Zone _onPointerDataPacketZone; 976 set onPointerDataPacket(PointerDataPacketCallback callback) { 977 _onPointerDataPacket = callback; 978 _onPointerDataPacketZone = Zone.current; 979 } 980 981 /// The route or path that the embedder requested when the application was 982 /// launched. 983 /// 984 /// This will be the string "`/`" if no particular route was requested. 985 /// 986 /// ## Android 987 /// 988 /// On Android, calling 989 /// [`FlutterView.setInitialRoute`](/javadoc/io/flutter/view/FlutterView.html#setInitialRoute-java.lang.String-) 990 /// will set this value. The value must be set sufficiently early, i.e. before 991 /// the [runApp] call is executed in Dart, for this to have any effect on the 992 /// framework. The `createFlutterView` method in your `FlutterActivity` 993 /// subclass is a suitable time to set the value. The application's 994 /// `AndroidManifest.xml` file must also be updated to have a suitable 995 /// [`<intent-filter>`](https://developer.android.com/guide/topics/manifest/intent-filter-element.html). 996 /// 997 /// ## iOS 998 /// 999 /// On iOS, calling 1000 /// [`FlutterViewController.setInitialRoute`](/objcdoc/Classes/FlutterViewController.html#/c:objc%28cs%29FlutterViewController%28im%29setInitialRoute:) 1001 /// will set this value. The value must be set sufficiently early, i.e. before 1002 /// the [runApp] call is executed in Dart, for this to have any effect on the 1003 /// framework. The `application:didFinishLaunchingWithOptions:` method is a 1004 /// suitable time to set this value. 1005 /// 1006 /// See also: 1007 /// 1008 /// * [Navigator], a widget that handles routing. 1009 /// * [SystemChannels.navigation], which handles subsequent navigation 1010 /// requests from the embedder. 1011 String get defaultRouteName => _defaultRouteName(); 1012 String _defaultRouteName() native 'Window_defaultRouteName'; 1013 1014 /// Requests that, at the next appropriate opportunity, the [onBeginFrame] 1015 /// and [onDrawFrame] callbacks be invoked. 1016 /// 1017 /// See also: 1018 /// 1019 /// * [SchedulerBinding], the Flutter framework class which manages the 1020 /// scheduling of frames. 1021 void scheduleFrame() native 'Window_scheduleFrame'; 1022 1023 /// Updates the application's rendering on the GPU with the newly provided 1024 /// [Scene]. This function must be called within the scope of the 1025 /// [onBeginFrame] or [onDrawFrame] callbacks being invoked. If this function 1026 /// is called a second time during a single [onBeginFrame]/[onDrawFrame] 1027 /// callback sequence or called outside the scope of those callbacks, the call 1028 /// will be ignored. 1029 /// 1030 /// To record graphical operations, first create a [PictureRecorder], then 1031 /// construct a [Canvas], passing that [PictureRecorder] to its constructor. 1032 /// After issuing all the graphical operations, call the 1033 /// [PictureRecorder.endRecording] function on the [PictureRecorder] to obtain 1034 /// the final [Picture] that represents the issued graphical operations. 1035 /// 1036 /// Next, create a [SceneBuilder], and add the [Picture] to it using 1037 /// [SceneBuilder.addPicture]. With the [SceneBuilder.build] method you can 1038 /// then obtain a [Scene] object, which you can display to the user via this 1039 /// [render] function. 1040 /// 1041 /// See also: 1042 /// 1043 /// * [SchedulerBinding], the Flutter framework class which manages the 1044 /// scheduling of frames. 1045 /// * [RendererBinding], the Flutter framework class which manages layout and 1046 /// painting. 1047 void render(Scene scene) native 'Window_render'; 1048 1049 /// Whether the user has requested that [updateSemantics] be called when 1050 /// the semantic contents of window changes. 1051 /// 1052 /// The [onSemanticsEnabledChanged] callback is called whenever this value 1053 /// changes. 1054 bool get semanticsEnabled => _semanticsEnabled; 1055 bool _semanticsEnabled = false; 1056 1057 /// A callback that is invoked when the value of [semanticsEnabled] changes. 1058 /// 1059 /// The framework invokes this callback in the same zone in which the 1060 /// callback was set. 1061 VoidCallback get onSemanticsEnabledChanged => _onSemanticsEnabledChanged; 1062 VoidCallback _onSemanticsEnabledChanged; 1063 Zone _onSemanticsEnabledChangedZone; 1064 set onSemanticsEnabledChanged(VoidCallback callback) { 1065 _onSemanticsEnabledChanged = callback; 1066 _onSemanticsEnabledChangedZone = Zone.current; 1067 } 1068 1069 /// A callback that is invoked whenever the user requests an action to be 1070 /// performed. 1071 /// 1072 /// This callback is used when the user expresses the action they wish to 1073 /// perform based on the semantics supplied by [updateSemantics]. 1074 /// 1075 /// The framework invokes this callback in the same zone in which the 1076 /// callback was set. 1077 SemanticsActionCallback get onSemanticsAction => _onSemanticsAction; 1078 SemanticsActionCallback _onSemanticsAction; 1079 Zone _onSemanticsActionZone; 1080 set onSemanticsAction(SemanticsActionCallback callback) { 1081 _onSemanticsAction = callback; 1082 _onSemanticsActionZone = Zone.current; 1083 } 1084 1085 /// Additional accessibility features that may be enabled by the platform. 1086 AccessibilityFeatures get accessibilityFeatures => _accessibilityFeatures; 1087 AccessibilityFeatures _accessibilityFeatures; 1088 1089 /// A callback that is invoked when the value of [accessibilityFeatures] changes. 1090 /// 1091 /// The framework invokes this callback in the same zone in which the 1092 /// callback was set. 1093 VoidCallback get onAccessibilityFeaturesChanged => _onAccessibilityFeaturesChanged; 1094 VoidCallback _onAccessibilityFeaturesChanged; 1095 Zone _onAccessibilityFlagsChangedZone; 1096 set onAccessibilityFeaturesChanged(VoidCallback callback) { 1097 _onAccessibilityFeaturesChanged = callback; 1098 _onAccessibilityFlagsChangedZone = Zone.current; 1099 } 1100 1101 /// Change the retained semantics data about this window. 1102 /// 1103 /// If [semanticsEnabled] is true, the user has requested that this function 1104 /// be called whenever the semantic content of this window changes. 1105 /// 1106 /// In either case, this function disposes the given update, which means the 1107 /// semantics update cannot be used further. 1108 void updateSemantics(SemanticsUpdate update) native 'Window_updateSemantics'; 1109 1110 /// Set the debug name associated with this window's root isolate. 1111 /// 1112 /// Normally debug names are automatically generated from the Dart port, entry 1113 /// point, and source file. For example: `main.dart$main-1234`. 1114 /// 1115 /// This can be combined with flutter tools `--isolate-filter` flag to debug 1116 /// specific root isolates. For example: `flutter attach --isolate-filter=[name]`. 1117 /// Note that this does not rename any child isolates of the root. 1118 void setIsolateDebugName(String name) native 'Window_setIsolateDebugName'; 1119 1120 /// Sends a message to a platform-specific plugin. 1121 /// 1122 /// The `name` parameter determines which plugin receives the message. The 1123 /// `data` parameter contains the message payload and is typically UTF-8 1124 /// encoded JSON but can be arbitrary data. If the plugin replies to the 1125 /// message, `callback` will be called with the response. 1126 /// 1127 /// The framework invokes [callback] in the same zone in which this method 1128 /// was called. 1129 void sendPlatformMessage(String name, 1130 ByteData data, 1131 PlatformMessageResponseCallback callback) { 1132 final String error = 1133 _sendPlatformMessage(name, _zonedPlatformMessageResponseCallback(callback), data); 1134 if (error != null) 1135 throw Exception(error); 1136 } 1137 String _sendPlatformMessage(String name, 1138 PlatformMessageResponseCallback callback, 1139 ByteData data) native 'Window_sendPlatformMessage'; 1140 1141 /// Called whenever this window receives a message from a platform-specific 1142 /// plugin. 1143 /// 1144 /// The `name` parameter determines which plugin sent the message. The `data` 1145 /// parameter is the payload and is typically UTF-8 encoded JSON but can be 1146 /// arbitrary data. 1147 /// 1148 /// Message handlers must call the function given in the `callback` parameter. 1149 /// If the handler does not need to respond, the handler should pass null to 1150 /// the callback. 1151 /// 1152 /// The framework invokes this callback in the same zone in which the 1153 /// callback was set. 1154 PlatformMessageCallback get onPlatformMessage => _onPlatformMessage; 1155 PlatformMessageCallback _onPlatformMessage; 1156 Zone _onPlatformMessageZone; 1157 set onPlatformMessage(PlatformMessageCallback callback) { 1158 _onPlatformMessage = callback; 1159 _onPlatformMessageZone = Zone.current; 1160 } 1161 1162 /// Called by [_dispatchPlatformMessage]. 1163 void _respondToPlatformMessage(int responseId, ByteData data) 1164 native 'Window_respondToPlatformMessage'; 1165 1166 /// Wraps the given [callback] in another callback that ensures that the 1167 /// original callback is called in the zone it was registered in. 1168 static PlatformMessageResponseCallback _zonedPlatformMessageResponseCallback(PlatformMessageResponseCallback callback) { 1169 if (callback == null) 1170 return null; 1171 1172 // Store the zone in which the callback is being registered. 1173 final Zone registrationZone = Zone.current; 1174 1175 return (ByteData data) { 1176 registrationZone.runUnaryGuarded(callback, data); 1177 }; 1178 } 1179} 1180 1181/// Additional accessibility features that may be enabled by the platform. 1182/// 1183/// It is not possible to enable these settings from Flutter, instead they are 1184/// used by the platform to indicate that additional accessibility features are 1185/// enabled. 1186// 1187// When changes are made to this class, the equivalent APIs in each of the 1188// embedders *must* be updated. 1189class AccessibilityFeatures { 1190 const AccessibilityFeatures._(this._index); 1191 1192 static const int _kAccessibleNavigation = 1 << 0; 1193 static const int _kInvertColorsIndex = 1 << 1; 1194 static const int _kDisableAnimationsIndex = 1 << 2; 1195 static const int _kBoldTextIndex = 1 << 3; 1196 static const int _kReduceMotionIndex = 1 << 4; 1197 1198 // A bitfield which represents each enabled feature. 1199 final int _index; 1200 1201 /// Whether there is a running accessibility service which is changing the 1202 /// interaction model of the device. 1203 /// 1204 /// For example, TalkBack on Android and VoiceOver on iOS enable this flag. 1205 bool get accessibleNavigation => _kAccessibleNavigation & _index != 0; 1206 1207 /// The platform is inverting the colors of the application. 1208 bool get invertColors => _kInvertColorsIndex & _index != 0; 1209 1210 /// The platform is requesting that animations be disabled or simplified. 1211 bool get disableAnimations => _kDisableAnimationsIndex & _index != 0; 1212 1213 /// The platform is requesting that text be rendered at a bold font weight. 1214 /// 1215 /// Only supported on iOS. 1216 bool get boldText => _kBoldTextIndex & _index != 0; 1217 1218 /// The platform is requesting that certain animations be simplified and 1219 /// parallax effects removed. 1220 /// 1221 /// Only supported on iOS. 1222 bool get reduceMotion => _kReduceMotionIndex & _index != 0; 1223 1224 @override 1225 String toString() { 1226 final List<String> features = <String>[]; 1227 if (accessibleNavigation) 1228 features.add('accessibleNavigation'); 1229 if (invertColors) 1230 features.add('invertColors'); 1231 if (disableAnimations) 1232 features.add('disableAnimations'); 1233 if (boldText) 1234 features.add('boldText'); 1235 if (reduceMotion) 1236 features.add('reduceMotion'); 1237 return 'AccessibilityFeatures$features'; 1238 } 1239 1240 @override 1241 bool operator ==(dynamic other) { 1242 if (other.runtimeType != runtimeType) 1243 return false; 1244 final AccessibilityFeatures typedOther = other; 1245 return _index == typedOther._index; 1246 } 1247 1248 @override 1249 int get hashCode => _index.hashCode; 1250} 1251 1252/// Describes the contrast of a theme or color palette. 1253enum Brightness { 1254 /// The color is dark and will require a light text color to achieve readable 1255 /// contrast. 1256 /// 1257 /// For example, the color might be dark grey, requiring white text. 1258 dark, 1259 1260 /// The color is light and will require a dark text color to achieve readable 1261 /// contrast. 1262 /// 1263 /// For example, the color might be bright white, requiring black text. 1264 light, 1265} 1266 1267/// The [Window] singleton. 1268/// 1269/// Please try to avoid statically referencing this and instead use a 1270/// binding for dependency resolution such as `WidgetsBinding.instance.window`. 1271/// 1272/// Static access of this "window" object means that Flutter has few, if any 1273/// options to fake or mock the given object in tests. Even in cases where Dart 1274/// offers special language constructs to forcefully shadow such properties, 1275/// those mechanisms would only be reasonable for tests and they would not be 1276/// reasonable for a future of Flutter where we legitimately want to select an 1277/// appropriate implementation at runtime. 1278/// 1279/// The only place that `WidgetsBinding.instance.window` is inappropriate is if 1280/// a `Window` is required before invoking `runApp()`. In that case, it is 1281/// acceptable (though unfortunate) to use this object statically. 1282final Window window = Window._(); 1283